How to make a m*2 matrix into n number of 2x2 matrices
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey,
I have, A = 208x2 matrix. I wish to to spit this matrix into 104 2x2 matrices. I have tried using num2cell and mat2cell but have had no luck. Any help would be appreicated.
Thanks.
Réponse acceptée
Plus de réponses (2)
KSSV
le 7 Sep 2022
A = rand(208,2) ;
[r,c] = size(A);
nlay = 104 ;
out = permute(reshape(A',[c,r/nlay,nlay]),[2,1,3]);
0 commentaires
Abderrahim. B
le 7 Sep 2022
Split A
A = randi(10, 208, 2) ; % a mtarix of size 208x2
size(A)
B = reshape(A, 2, 2, []) ;
Access 2x2 matrices
B1 = B(:,:,1)
B2 = B(:,:,2)
Hope this helps
2 commentaires
Stephen23
le 7 Sep 2022
Modifié(e) : Stephen23
le 7 Sep 2022
Note that this method does not keep the 2x2 matrices of the original matrix:
A = randi(10, 208, 2)
B = reshape(A, 2,2,[]) % not the same matrices
To keep the original matrices requires taing into account the order of elements stored in memory:
B = permute(reshape(A.',2,2,[]),[2,1,3])
Abderrahim. B
le 7 Sep 2022
Thanks @Stephen23. But he does not mention that the order must be te same as in the original matrix!
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!