How to trasform from cell to matrix and transpose from horizontal to vertical at the same time?
조회 수: 9 (최근 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!