Concatenate cell arrays element-wise

조회 수: 3 (최근 30일)
sushma sharma
sushma sharma 2015년 3월 22일
편집: Andrei Bobrov 2015년 3월 22일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 3월 22일
편집: Andrei Bobrov 2015년 3월 22일
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개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by