dede
dede

Reputation: 1171

convert 3d cell array in 2d cell array

I transformed a structure S (with 13 fields and 96 rows, some fields are made of numbers, others of strings) into a cell array:

myCell= struct2cell(S);

So, I obtained a 3d cell array myCell 13x1x96, and I would like to transform it in a 2d cell array 96x13. Any suggestion is welcome!

Upvotes: 0

Views: 333

Answers (1)

Dev-iL
Dev-iL

Reputation: 24159

A more general solution than what was suggested would employ the permute function:

B = permute(A,order) rearranges the dimensions of A so that they are in the order specified by the vector order.

...

permute and ipermute are a generalization of transpose (.') for multidimensional arrays.

In your case, running the command new_Cell = permute(myCell,[3,1,2]) would make the 13x1x96 96x13. As you can see, permute removes trailing singleton dimensions (resembling squeeze).

(Tested on MATLAB 2015b)

Upvotes: 1

Related Questions