How to trasform from cell to matrix and transpose from horizontal to vertical at the same time?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tomaszzz
le 28 Sep 2022
Réponse apportée : J. Alex Lee
le 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 commentaires
Réponse acceptée
Chunru
le 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 commentaires
Plus de réponses (1)
J. Alex Lee
le 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 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!