Filter löschen
Filter löschen

How to merge str array with double array?

1 Ansicht (letzte 30 Tage)
Julien Pezet
Julien Pezet am 27 Feb. 2019
Kommentiert: Julien Pezet am 27 Feb. 2019
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!

Akzeptierte Antwort

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

Weitere Antworten (2)

KSSV
KSSV am 27 Feb. 2019
A = {'21/02'
'22/02'
'25/02'}
B = [2 7 9
5 7 0
3 6 1]
iwant = strcat(A,{' '},num2str(B))
  1 Kommentar
Julien Pezet
Julien Pezet am 27 Feb. 2019
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'}

Melden Sie sich an, um zu kommentieren.


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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by