Concatenate cell arrays element-wise
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sushma sharma
am 22 Mär. 2015
Bearbeitet: Andrei Bobrov
am 22 Mär. 2015
Hi, I have two cell arrays: A = {'a','b'}, and C = {'c','d'}.
How can I write a loop to take each element of A and concatenated it with each element of C?
Result = {'ac','ad','bc','bd'}
Any help would be appreciated! Thanks,
Sushma
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 22 Mär. 2015
Bearbeitet: Andrei Bobrov
am 22 Mär. 2015
out = strcat(A(kron(1:2,[1,1])),C(kron([1,1],1:2)));
or
[y,x]=ndgrid(1:2);
out = strcat(A(x(:)),C(y(:)));
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!