How to trasform from cell to matrix and transpose from horizontal to vertical at the same time?
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chunru
2022-9-28
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 个评论
更多回答(1 个)
J. Alex Lee
2022-9-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!