jhc
jhc

Reputation: 1769

Convert 3D array to cell of 2D arrays

I use octave, but matlab users will probably be just as helpful.

I have an an array defined in space m x n and in time, t. Therefore it has size m x n x t. For a certain function, it would be much more helpful to convert this 3D dimension into a cell with the following structure:

Consider A to be the m x n x t array.

cell = {A(:,:,1), A(:,:,2), ..., A(:,:,t)}, that has t element, each element an m x n array.

I don't know how to do this for dynamic t.

Upvotes: 3

Views: 3262

Answers (1)

Mohsen Nosratinia
Mohsen Nosratinia

Reputation: 9864

You can use mat2cell to achieve it:

[m n t] = size(A);
B=mat2cell(A, m, n, ones(1,t));

Upvotes: 4

Related Questions