Matlab1*n数组 按照指定的order排列成8*8的矩阵。
4 views (last 30 days)
Show older comments
随机64个数组成一个1*64的数组,要求按照下面的这种方式从小到大排列成8*8的矩阵,应该如何操作?

由此推导到更大维度的应该如何操作?
0 Comments
Accepted Answer
hvxfnug
on 21 May 2023
N = 8;
M = toeplitz( [ ones( 1, N ), zeros( 1, N ) ], [ 1, zeros( 1, N - 1 ) ] );
M = M( 1 : end - 1, : ).';
M( M ~= 0 ) = 1 : N^2;
M = M.'; M( M == 0 ) = [];
M = reshape( M, [ N, N ] ).';
disp( M )
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!