MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   将N ^ 2个3x3矩阵级联为3Nx3N矩阵 (https://www.labfans.com/bbs/showthread.php?t=26283)

poster 2019-12-14 20:13

将N ^ 2个3x3矩阵级联为3Nx3N矩阵
 
我有N ^ 2个矩阵。每个都是3x3矩阵。将它们串联到3Nx3N矩阵的一种方法是编写A(:,:,i)= # 3x3 matrix i=1:N^2

[IMG]https://i.stack.imgur.com/podvp.png[/IMG]

B=[A11 A12 ..A1N;A21 ...A2N;...]但是,当N大时,是一项繁琐的工作。您提供什么?



[B]回答:[/B]

这是一个非常快的[URL="http://www.mathworks.com/help/techdoc/ref/reshape.html"]单线[/URL] ,仅使用[URL="http://www.mathworks.com/help/techdoc/ref/reshape.html"]RESHAPE[/URL]和[URL="http://www.mathworks.com/help/techdoc/ref/permute.html"]PERMUTE[/URL] :

B = reshape(permute(reshape(A,3,3*N,N),[2 1 3]),3*N,3*N).'; 并进行测试:

>> N=2; >> A = rand(3,3,N^2) A(:,:,1) = 0.5909 0.6571 0.8082 0.7118 0.6090 0.7183 0.4694 0.9588 0.5582 A(:,:,2) = 0.1791 0.6844 0.6286 0.4164 0.4140 0.5833 0.1380 0.1099 0.8970 A(:,:,3) = 0.2232 0.2355 0.1214 0.1782 0.6873 0.3394 0.5645 0.4745 0.9763 A(:,:,4) = 0.5334 0.7559 0.9984 0.8454 0.7618 0.1065 0.0549 0.5029 0.3226 >> B = reshape(permute(reshape(A,3,3*N,N),[2 1 3]),3*N,3*N).' B = 0.5909 0.6571 0.8082 0.1791 0.6844 0.6286 0.7118 0.6090 0.7183 0.4164 0.4140 0.5833 0.4694 0.9588 0.5582 0.1380 0.1099 0.8970 0.2232 0.2355 0.1214 0.5334 0.7559 0.9984 0.1782 0.6873 0.3394 0.8454 0.7618 0.1065 0.5645 0.4745 0.9763 0.0549 0.5029 0.3226

[url=https://stackoverflow.com/questions/4897989]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 09:38

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.