HOW TO COMBINE TWO CELLS INTO ONE?

7 ビュー (過去 30 日間)
Gili Kurtser
Gili Kurtser 2019 年 10 月 18 日
編集済み: dpb 2019 年 10 月 18 日
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
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
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 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by