Concatenate multiple cell into a single cell

3 vues (au cours des 30 derniers jours)
eko supriyadi
eko supriyadi le 3 Juin 2022
Commenté : Voss le 4 Juin 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 :)

Réponse acceptée

Voss
Voss le 3 Juin 2022
Modifié(e) : Voss le 3 Juin 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 commentaires
Voss
Voss le 4 Juin 2022
("Answer" from @eko supriyadi moved here:)
wow brilliant..thank you for your effort..
ES.
Voss
Voss le 4 Juin 2022
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by