How to divide a 3D array into one dimensional cell array

8 visualizaciones (últimos 30 días)
Alon Rozen
Alon Rozen el 25 de Dic. de 2017
Respondida: Star Strider el 25 de Dic. de 2017
Hi,
I have a 3x3xn Array which actually contains n times 3x3 matrices. I want to convert it to a one dimensional cell array with n entries (nx1) so that the ith cell contains the ith 3x3 matrix. I know that the key functions to use are 'mat2cell' and 'num2cell' but I can't get it right. It is important that the cell array will be only one dimensional because it should enter to a 'table' as one of the fields.
Any help will be appreciated! Alon

Respuestas (1)

Star Strider
Star Strider el 25 de Dic. de 2017
Use the mat2cell function:
M = randi(9, 3, 3, 2) % Create Matrix
Msz = size(M); % Get Size
C = mat2cell(M, Msz(1), Msz(2), ones(1,Msz(3))); % Convert To Cells, One ‘Page’ Per Cell
C{1} % View Output (Optional)
C{2} % View Output (Optional)

Categorías

Más información sobre Matrix Indexing 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