HOW TO COMBINE TWO CELLS INTO ONE?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Gili Kurtser
el 18 de Oct. de 2019
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 comentario
Adam
el 18 de Oct. de 2019
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'
Respuesta aceptada
dpb
el 18 de Oct. de 2019
Editada: dpb
el 18 de Oct. de 2019
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Time Series Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!