Concatenate multiple cell into a single cell

3 Ansichten (letzte 30 Tage)
eko supriyadi
eko supriyadi am 3 Jun. 2022
Kommentiert: Voss am 4 Jun. 2022
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 :)

Akzeptierte Antwort

Voss
Voss am 3 Jun. 2022
Bearbeitet: Voss am 3 Jun. 2022
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 Kommentare
Voss
Voss am 4 Jun. 2022
("Answer" from @eko supriyadi moved here:)
wow brilliant..thank you for your effort..
ES.
Voss
Voss am 4 Jun. 2022
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by