Concatenate multiple cell into a single cell

조회 수: 3 (최근 30일)
eko supriyadi
eko supriyadi 2022년 6월 3일
댓글: Voss 2022년 6월 4일
Hi all,
I have cell (many cell) array that contains varying length in row direction. For example see below ilustration:
ncell1={'12','21','44','02','35'}; % 1x5 cell
ncell2={'03','21','45','45','11'}; % 1x5 cell
ncell3={'23','15','47','36','35','78'}; % 1x6 cell
ncell4={'47','28','99'}; % 1x3 cell
ncell={ncell1 ncell2 ncell3 ncell4}.'; %-->4x1 cell
the problem, how can i concatenate 4 cells those to 1 cell with 4x6 cell dimension size (yes, 4x6 size! not 4x1 or 1x4 or 1x1). So the result what i want like (note: the ncell5 below just copy paste ncell1-4 for easy ilustration) :
so far have i do:
result = cat(1,ncell); %same with result ncell
result = {[ncell(1) ncell(2) .... ]} %only combine the dimensions of the cells
result = [char(ncell{1}), char(ncell{2}) ....]; %character not uniform
remember i work with hundred ncell. tks for your help :)

채택된 답변

Voss
Voss 2022년 6월 3일
편집: Voss 2022년 6월 3일
ncell1={'12','21','44','02','35'}; % 1x5 cell
ncell2={'03','21','45','45','11'}; % 1x5 cell
ncell3={'23','15','47','36','35','78'}; % 1x6 cell
ncell4={'47','28','99'}; % 1x3 cell
ncell={ncell1; ncell2; ncell3; ncell4}; %-->4x1 cell
m = numel(ncell);
n = cellfun(@numel,ncell); % n = [5; 5; 6; 3]
ncell2d = cell(m,max(n)); % 4x6 cell (!)
for ii = 1:m
ncell2d(ii,1:n(ii)) = ncell{ii};
end
disp(ncell2d);
{'12'} {'21'} {'44'} {'02' } {'35' } {0×0 double} {'03'} {'21'} {'45'} {'45' } {'11' } {0×0 double} {'23'} {'15'} {'47'} {'36' } {'35' } {'78' } {'47'} {'28'} {'99'} {0×0 double} {0×0 double} {0×0 double}
  댓글 수: 2
Voss
Voss 2022년 6월 4일
("Answer" from @eko supriyadi moved here:)
wow brilliant..thank you for your effort..
ES.
Voss
Voss 2022년 6월 4일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by