How to make a cell array of cell arrays

9 vues (au cours des 30 derniers jours)
Blue
Blue le 6 Août 2019
Modifié(e) : madhan ravi le 6 Août 2019
Hi,
How does one make a cell array of cell array in Matlab ? Let's A = (1:70), how can I transform this into a 14x1 cell array for which every cell contains 5 numbers ?
Thank you
  1 commentaire
Adam Danz
Adam Danz le 6 Août 2019
Ha! You got 2 answers at almost the same time with almost the same variable names and the same explanation of terminology.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 6 Août 2019
Modifié(e) : Adam Danz le 6 Août 2019
"how can I transform this into a 14x1 cell array for which every cell contains 5 numbers"
What you're describing is a cell array of vectors, not a cell array of cells.
c = mat2cell(reshape(A,5,14),5,ones(1,14)); % For column vectors
or
c = mat2cell(reshape(A,5,14)',ones(1,14),5); % For row vectors
  1 commentaire
Blue
Blue le 6 Août 2019
Thank you Adam.

Connectez-vous pour commenter.

Plus de réponses (2)

the cyclist
the cyclist le 6 Août 2019
Here is one way:
A = 1:70;
C = cell(14,1);
for ii = 1:14
C{ii} = A(5*ii-4:5*ii);
end
To be clear on terminology (and what you actually want) ... this will be a cell array of numeric vectors, not a cell array of cell arrays.

madhan ravi
madhan ravi le 6 Août 2019
Modifié(e) : madhan ravi le 6 Août 2019
Wanted = num2cell(reshape(A,5,[]),1).'

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by