0

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!

4
  • 2
    something like (squeeze(myCell)).' perhaps? The squeeze removes the singleton dimension. Commented Nov 20, 2015 at 11:46
  • @Benoit_11, thanks for your answer. I tried, and now myCell is 13x96, so at least 2d cell array, which is very good :). How can I now swap the rows with the columns and viceversa, in order to have myCell as 96x13? Commented Nov 20, 2015 at 11:53
  • 1
    @dede Transpose the output: result = myCell.' Commented Nov 20, 2015 at 11:54
  • @mikkola, thanks :) It works perfectly!! Commented Nov 20, 2015 at 11:55

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.