How to concatenate 2 cell arrays containing strings?

조회 수: 8 (최근 30일)
Travis Leith
Travis Leith 2019년 10월 24일
댓글: Travis Leith 2019년 10월 24일
I have something like this
x = arrayfun(@(i) sprintf("%s%i", 'xx', i), (0:6)');
which generates a 7x1 string array and behaves the way I want.
But I want to apply this to a variety of prefix strings as in.
s = ["xx"; "yy"];
x = arrayfun(@(s) arrayfun(@(i) sprintf("%s%i", 'LA', i), (0:6)'), s);
But this raises an error and changing it to
x = arrayfun(@(s) arrayfun(@(i) sprintf("%s%i", 'LA', i), (0:6)'), s, 'UniformOutput', false);
runs, but now generates a 2x1 cell array, each cell containing a 7x1 string array.
What I really want is a 14x1 string array. cell2mat does not work for this.
I realise I can get this done with a loop, but I prefer to code (and think) declaratively. Can this be done without a loop?

채택된 답변

Adam
Adam 2019년 10월 24일
vertcat( x{:} )

추가 답변 (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