poster
2019-12-14, 20:13
我有N ^ 2个矩阵。每个都是3x3矩阵。将它们串联到3Nx3N矩阵的一种方法是编写A(:,:,i)= # 3x3 matrix i=1:N^2
https://i.stack.imgur.com/podvp.png
B=[A11 A12 ..A1N;A21 ...A2N;...]但是,当N大时,是一项繁琐的工作。您提供什么?
回答:
这是一个非常快的单线 (http://www.mathworks.com/help/techdoc/ref/reshape.html) ,仅使用RESHAPE (http://www.mathworks.com/help/techdoc/ref/reshape.html)和PERMUTE (http://www.mathworks.com/help/techdoc/ref/permute.html) :
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
更多&回答... (https://stackoverflow.com/questions/4897989)
https://i.stack.imgur.com/podvp.png
B=[A11 A12 ..A1N;A21 ...A2N;...]但是,当N大时,是一项繁琐的工作。您提供什么?
回答:
这是一个非常快的单线 (http://www.mathworks.com/help/techdoc/ref/reshape.html) ,仅使用RESHAPE (http://www.mathworks.com/help/techdoc/ref/reshape.html)和PERMUTE (http://www.mathworks.com/help/techdoc/ref/permute.html) :
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
更多&回答... (https://stackoverflow.com/questions/4897989)