Concatenate multiple cell into a single cell

3 visualizaciones (últimos 30 días)
eko supriyadi
eko supriyadi el 3 de Jun. de 2022
Comentada: Voss el 4 de Jun. de 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 :)

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by