add column to matrix that allows to identify series

1 vue (au cours des 30 derniers jours)
Locks
Locks le 15 Sep 2014
Commenté : Locks le 16 Sep 2014
Hi,
I have the following problem:
I constructed a matrix from several timeseries and I need to add a column to the matrix with the identifier of the respective series. Here an example:
series1=[1 1000; 2 990]
series2=[1 750; 2 780]
series3=[1 1250; 3 1150]
seriesCompl=[series1; series2; series3]
what I need in addition is now a column in matrix seriesCompl where I can see which series it is.
The outcome should look like
1 1000 series1
2 990 series1
1 750 series2
2 780 series2
1 1250 series3
3 1150 series3

Réponse acceptée

Roger Wohlwend
Roger Wohlwend le 16 Sep 2014
If you want to combine numbers and texts in a matrix you have to create a cell matrix, a dataset or a table. However, I am not sure I you really want to do that. The solution to your problem depends on what you want to do with the matrix seriesCompl. If you want to perform calcualtions or plot the data in the matrix, then it would be wise to keep the matrix numerical. Instead of writing a name in the third column you could use numbers: series1 = 1, series2 = 2, series3 = 3, ... If you have other plans, then you have to choose a different data type for your matrix (cell, dataset or table).
  1 commentaire
Locks
Locks le 16 Sep 2014
I will use a number as unique identifier for the series, thanks a lot

Connectez-vous pour commenter.

Plus de réponses (1)

Adam
Adam le 16 Sep 2014
As you have it there 'series1', etc are just variable names. I would assume you are not planning on keeping all the individual variables around as well as the combined matrix so since the variable name is not really relevant to store along with the data could you not just add a numeric column of 1, 2 or 3 for which series each row belongs to?

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by