HOW TO COMBINE TWO CELLS INTO ONE?

8 次查看(过去 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
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by