Matlab1*n数组 按照指定的order排列成8*8的矩阵。

4 views (last 30 days)
fnytqky
fnytqky on 21 May 2023
Answered: hvxfnug on 21 May 2023
随机64个数组成一个1*64的数组,要求按照下面的这种方式从小到大排列成8*8的矩阵,应该如何操作?
由此推导到更大维度的应该如何操作?

Accepted Answer

hvxfnug
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 )

More Answers (0)

Categories

Find more on 软件开发工具 in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!