Hi everyone,
I have 12 series:
x1 = [1990M1, 1991M1, 1992M1 .....2020M1]
x2=[1990M2, 1991M2, 1992M2 ...2020M2]
...
x12=[1990M12, 1991M12, 1992M12 ...2020M12]
Now I would like a time sereis:
x= [1990M1, 1990M2, 1990M3 ...2020M12].
Please give me a hint.
Many thanks,
Bao

2 件のコメント

Mehmed Saad
Mehmed Saad 2020 年 4 月 17 日
if they are of same length just put
y = [x1;x2;x3;x4;x5;x6;x7;x8;x9;x10;x11;x12];
x = y(:,1);
Nguyen Bao
Nguyen Bao 2020 年 4 月 18 日
Thanks, but this is not the solution.

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 17 日
編集済み: Ameer Hamza 2020 年 4 月 18 日

0 投票

First, you should avoid creating variables names like x1, x2, ..., xn. This thread explains the issues with this approach in detail: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
Now, if you want to correct this issue by combining all these values in a single array, then you can use eval(). Note that using frequently using eval() in your code is not a very good idea and should be avoided, but you can use it once to fix the initial mistakes. This code shows an example.
x1 = [1 2 3];
x2 = [4 5 6];
x3 = [7 8 9];
x4 = [10 11 12];
x5 = [13 14 15];
x = [];
for i=1:5 % numbers of the x variables
eval(['x = [x; x' num2str(i) '];']);
end
x = x(:)';

3 件のコメント

Nguyen Bao
Nguyen Bao 2020 年 4 月 17 日
Thanks Ameer,
In fact, I would like to see:
x= [1 4 7 10 13 2 5 8 11 14 3 6 9 12 15]
This is because, I have 12 balanced separate series contain data of 12 months for several years, now I want to put them together to get a signle time series for those years continuously. For example, x1 contains values in Jan from 1990 to 2020, x2 is in Feb from 1990 to 2020 ....Thus, I want to see a series x = 1990 Jan, 1990 Feb .....2020 Dec.
Cheers,
Ameer Hamza
Ameer Hamza 2020 年 4 月 18 日
Nguyen, please try the updated code.
Nguyen Bao
Nguyen Bao 2020 年 4 月 18 日
Perfect, thanks Ameer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2020 年 4 月 17 日

コメント済み:

2020 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by