MATLAB Answers

How to transpose a cell array ?

417 views (last 30 days)
SUSHMA MB
SUSHMA MB on 2 Dec 2015
Commented: Luke Aucoin on 24 Sep 2020
Each cell in the cell array contains a matrix, e.g.,
Suppose the cell array is
[8x1] cell
Inside which their are some matrix like
[6x2] double
[7x2] double
[6x2] double
[7x2] double
[6x2] double
[7x2] double
[6x2] double
[7x2] double
Now i want to transpose the cell array into
[1x8] cell
How to do it?

  0 Comments

Sign in to comment.

Accepted Answer

SUSHMA MB
SUSHMA MB on 2 Dec 2015
reshape command works for this example well. For poly as the name of the cell array,
polyre = reshape(poly,[1 8]);

  0 Comments

Sign in to comment.

More Answers (1)

the cyclist
the cyclist on 2 Dec 2015
Edited: the cyclist on 2 Dec 2015
To transpose the cell array itself:
C_transposed = C';
To transpose the matrices inside:
C_inside = cellfun(@transpose,C,'UniformOutput',false)

  3 Comments

SUSHMA MB
SUSHMA MB on 2 Dec 2015
Thank you for the answer. I tried the above one but its not working.
Murari Mandal
Murari Mandal on 4 Nov 2016
It is working just fine.
Luke Aucoin
Luke Aucoin on 24 Sep 2020
I used C_transposed = C' to transform a row array of character strings into a column array of the same strings. Thanks @the cyclist.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!