Effacer les filtres
Effacer les filtres

Problem in string-number concatenation

1 vue (au cours des 30 derniers jours)
Annika
Annika le 21 Août 2014
Commenté : Annika le 21 Août 2014
hello, I am trying to concatenate two matrices, A=['a1';'a2';'a3';'a4'] and Z=[190;64;4;5]. I am not able to do so.
Can someone help please. Thanks Annika
  1 commentaire
Hikaru
Hikaru le 21 Août 2014
What kind of format do you want for the output?

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 21 Août 2014
use cell array
A={'a1';'a2';'a3';'a4'};
Z=[190;64;4;5];
out = [A, num2cell(Z)];
  1 commentaire
Annika
Annika le 21 Août 2014
Thanks for the reply. It does work for this example. But when i used the same in my original program, there is a error. I suppose i could not convey the right problem with the small example. I write my original code here
if true
E='SSFx';
F='VSS1Fx';
G='VSS2Fx';
H='NSFy';
I='SSFy';
J='VSS1Fy';
K='VSS2Fy';
L='NSFz';
M='SSFz';
N='VSS1Fz';
O='VSS2Fz';
P='NSMx';
Q='SSMx';
R='VSS1Mx';
S='VSS2Mx';
T='NSMy';
U='SSMy';
V='VSS1My';
W='VSS2My';
X='NSMz';
Y='SSMz';
Z='VSS1Mz';
D='VSS2Mz';
A=['E';'F';'G';'H';'I';'J';'K';'L';'M';'N';'O';'P';'Q';'R';'S';'T';'U';'V';'W';'X';'Y';'Z';'D']
B=Iy';
r=[A,num2cell(B)];
end
where Iy =
190 64 4 5 190 95 4 190 65 65 150 190 190 66 185 5 190 43 185 2 5 100 4
Thanks

Connectez-vous pour commenter.

Plus de réponses (1)

David Sanchez
David Sanchez le 21 Août 2014
Define your A array as a cell using brackets { }:
A={'E';'F';'G';'H';'I';'J';'K';'L';'M';'N';'O';'P';'Q';'R';'S';'T';'U';'V';'W';'X';'Y';'Z';'D'};
Iy =[ 190 64 4 5 190 95 4 190 65 65 150 190 190 66 185 5 190 43 185 2 5 100 4];
B=Iy';
r=[A,num2cell(B)];

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by