Merge rows of cell array with strings per column?

조회 수: 1 (최근 30일)
Jonathan
Jonathan 2022년 10월 4일
댓글: Jonathan 2022년 10월 4일
I have a cell array of 2xn with strings and I would like to merge the text of all rows on a per column base, effectively yielding a 1xn cell array. To illustrate I have something like this...
[{'A'} {'C'}; {'B'} {'D'}]
ans = 2×2 cell array
{'A'} {'C'} {'B'} {'D'}
... and would like something like this:
[{'AB'} {'CD'}]
ans = 1×2 cell array
{'AB'} {'CD'}

채택된 답변

Stephen23
Stephen23 2022년 10월 4일
C = {'A','C'; 'B','D'}
C = 2×2 cell array
{'A'} {'C'} {'B'} {'D'}
D = cellfun(@(c)join(c,''),num2cell(C,1))
D = 1×2 cell array
{'AB'} {'CD'}
D = cellfun(@(c)[c{:}],num2cell(C,1),'uni',0)
D = 1×2 cell array
{'AB'} {'CD'}

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by