How to trasform from cell to matrix and transpose from horizontal to vertical at the same time?
9 views (last 30 days)
Show older comments
Hi all,
I have a structure with a 3x1 cell. The cell contains 1x101 matrices.
I want to access the cell and trasform it to matrix but at the same time transpose it from horizontal to vertical.
My approach:
my_matrix = cat(2, Data.my_cell{:});
results in 1x303 matrix. However I want the end product to be a 101x3 matrix. Can you help?
0 Comments
Accepted Answer
Chunru
on 28 Sep 2022
Data.my_cell{1} = randn(1, 11);
Data.my_cell{2} = randn(1, 11);
Data.my_cell{3} = randn(1, 11);
Data.my_cell
my_matrix = cell2mat(Data.my_cell(:))'
0 Comments
More Answers (1)
J. Alex Lee
on 28 Sep 2022
Just change your cat dimension to 1, then transpose later.
Data.my_cell = {rand(1,101);rand(1,101);rand(1,101)}
m = cat(1,Data.my_cell{:})'
check that it is the same as having transposed each array in the cell first, then cat-ing
c = cellfun(@transpose,Data.my_cell,"uni",false);
p = [c{:}];
isequal(p,m)
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!