Converting Cell Array into Array

28 vues (au cours des 30 derniers jours)
MByk
MByk le 11 Jan 2019
Modifié(e) : MByk le 25 Juin 2020
I have 4 matrices with fixed columns but different rows (4 * n-by-3) created inside a for loop. I am storing them in a cell array but I cant convert it into array using "cell2mat" function. Is there way to convert the cell array or a better way to store the results may be without any cell to array conversion? Thanks for the help.
for i=1:4
% Some calculations here
rSet = ...
C{i,1} = {rSet};
end
cell2mat(C);
% Error using cell2mat (line 52)
% CELL2MAT does not support cell arrays containing cell arrays or objects.

Réponse acceptée

madhan ravi
madhan ravi le 11 Jan 2019
Modifié(e) : madhan ravi le 11 Jan 2019
C=cell(1,4); % Preallocate before loop
C{i}...
% ^-—- is enough
vertcat(C{:}) %outside loop% or
[C{:}]

Plus de réponses (1)

Stephen23
Stephen23 le 11 Jan 2019
for i=1:4
% Some calculations here
rSet = ...
C{i,1} = rSet;
end
vertcat(C{:})
  1 commentaire
MByk
MByk le 11 Jan 2019
Thank you both.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by