How can I shuffle a matrix
4 ビュー (過去 30 日間)
古いコメントを表示
I have matrix nxn, A=[1 2 3 4;5 6 7 8; 9 10 11 12; 13 14 15 16]; I want to shuffle this matrix, which will give AB=[1 2 5 6; 3 4 7 8; 9 10 13 14; 11 12 15 16]. Any help will be highly appreciated, Rosi.
0 件のコメント
採用された回答
Stephen23
2018 年 1 月 14 日
Here are two methods to rearrange it according to your question. Adjust to suit the size of your matrix.
>> A=[1 2 3 4;5 6 7 8; 9 10 11 12; 13 14 15 16]
A =
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
>> cell2mat(reshape(cellfun(@(m)reshape(m.',2,2).',num2cell(A,2),'uni',0),2,2).')
ans =
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
>> reshape(permute(reshape(permute(reshape(A.',2,2,[]),[1,3,2]),4,2,[]),[1,3,2]),4,[]).'
ans =
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!