add column to matrix that allows to identify series
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Roger Wohlwend
2014-9-16
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 个)
Adam
2014-9-16
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?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!