How to make a m*2 matrix into n number of 2x2 matrices
3 次查看(过去 30 天)
显示 更早的评论
采纳的回答
更多回答(2 个)
KSSV
2022-9-7
A = rand(208,2) ;
[r,c] = size(A);
nlay = 104 ;
out = permute(reshape(A',[c,r/nlay,nlay]),[2,1,3]);
0 个评论
Abderrahim. B
2022-9-7
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 个评论
Stephen23
2022-9-7
编辑:Stephen23
2022-9-7
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
2022-9-7
Thanks @Stephen23. But he does not mention that the order must be te same as in the original matrix!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!