How to trasform from cell to matrix and transpose from horizontal to vertical at the same time?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tomaszzz
am 28 Sep. 2022
Beantwortet: J. Alex Lee
am 28 Sep. 2022
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 Kommentare
Akzeptierte Antwort
Chunru
am 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 Kommentare
Weitere Antworten (1)
J. Alex Lee
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!