Combine two cell arrays containing string values into one.

조회 수: 10 (최근 30일)
Marc Jakobi
Marc Jakobi 2013년 9월 25일
댓글: Johannes Rebling 2020년 4월 7일
Hi.
I have two cell arrays that look something like this:
A = {'1.'; '2.'; '3.'; '4.', '5.'};
B = {'A'; 'B'; 'C'; 'D'; 'E'};
Both are of the same length.
I want to combine them into a third cell array that looks like this:
C = {'1. A'; '2. B'; '3. C'; '4. D'; '5. E'};
How can I do this?
Thanks!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 25일
편집: Azzi Abdelmalek 2013년 9월 25일
A = {'1.'; '2.'; '3.'; '4.'; '5.'};
B = {'A'; 'B'; 'C'; 'D'; 'E'};
C=cellfun(@(x,y) [x ' ' y],A,B,'un',0)
  댓글 수: 3
Katharina
Katharina 2020년 3월 10일
Perfect, Thanks!
Johannes Rebling
Johannes Rebling 2020년 4월 7일
For those like me, wondering what the 'un',0 at the end of cellfun means, it's the same as 'UniformOutput',true. Thanks for the solution!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by