HOW TO COMBINE TWO CELLS INTO ONE?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everyone
I have to arrays witch I want to combine:
M=[ 1 2 4 7 8 9].';
Y=[2018 2018 2018 2018 2018].';
and I want to get
[1-2018
4-2018
...] and so
how can I do this?
Tnx
1 件のコメント
Adam
2019 年 10 月 18 日
They don't look like cell arrays, just numeric arrays.
Also
1-2018
is not a valid value to have in a numeric array.
You can concatenate two column vectors easily as
[M, Y]
if they are the same length, but you'll still have two columns. You'd have to format them into a string if you literally want '1-2018'
採用された回答
dpb
2019 年 10 月 18 日
編集済み: dpb
2019 年 10 月 18 日
As Adam notes, you have two arrays as shown (I took the liberty to reformat the original Q? to make more legible) and there's a mismatch in lengths so can't directly...that's probably just a typo in the posting one presumes.
Given they're month and year values, I'd suggest to convert to datetime instead; you can get the display format to be whatever you wish and do all kinds of magic with the values once have done...
t=datetime(Y,M,1,'Format','M-yyyy');
Example:
>> datetime(2018,[1;4],1,'Format','M-yyyy')
ans =
2×1 datetime array
1-2018
4-2018
>>
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!