Concatenate cell arrays element-wise
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
sushma sharma
le 22 Mar 2015
Modifié(e) : Andrei Bobrov
le 22 Mar 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 commentaires
Réponse acceptée
Andrei Bobrov
le 22 Mar 2015
Modifié(e) : Andrei Bobrov
le 22 Mar 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!