How to merge str array with double array?

1 次查看(过去 30 天)
Hello all,
I have a cell array A and a double array B like the following:
A = {'21/02'
'22/02'
'25/02'}
B = [2 7 9
5 7 0
3 6 1]
I would like to merge them in order to obtain C like:
C = {'21/02' '2' '7' '9'
'22/02' '5' '7' '0'
'25/02' '3' '6' '1'}
But I'm stuck. I would appreciate any help!

采纳的回答

Jan
Jan 2019-2-27
编辑:Jan 2019-2-27
A = {'21/02'; ...
'22/02'; ...
'25/02'}
B = [2 7 9; ...
5 7 0; ...
3 6 1]
C = [A, sprintfc('%d', B)]

更多回答(2 个)

KSSV
KSSV 2019-2-27
A = {'21/02'
'22/02'
'25/02'}
B = [2 7 9
5 7 0
3 6 1]
iwant = strcat(A,{' '},num2str(B))
  1 个评论
Julien Pezet
Julien Pezet 2019-2-27
Thanks for your reply,
I gives me:
iwant = {'21/02 2 7 9'
'22/02 5 7 0'
'25/02 3 6 1'}
instead of:
iwant = {'21/02' '2' '7' '9'
'22/02' '5' '7' '0'
'25/02' '3' '6' '1'}

请先登录,再进行评论。


madhan ravi
madhan ravi 2019-2-27
C=cellstr([string(A),""+B])
  1 个评论
Julien Pezet
Julien Pezet 2019-2-27
Thanks Madhan! I did not mention that my B contains Nan, and your answer deletes them.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by