Reshaping a matrix in particular order

1 次查看(过去 30 天)
Hi, I have a random size matrix with rows a multiple of 7 and columns a multiple of 4. (e.g. 14x8, 28x12). I want to reshape the matrix into a 7x4xn matrix with additional values going into a third (n) dimension (e.g. 14x8 becomes 7x4x4). I know how to use reshape but it changes the order in which i want to generate the 3D matrix. As an example consider:
A = [1,2,3,4;5,6,7,8;9,10,11,12;13,14,15,16]
% gives a 4x4 matrix like
% A = 1 2 3 4
% 5 6 7 8
% 9 10 11 12
% 13 14 15 16
%reshape(A,2,2,[]) gives
ans(:,:,1) = [1 9
5 13]
ans(:,:,2) = [2 10
6 14]
ans(:,:,3) = [3 11
7 15]
ans(:,:,4) = [4 12
8 16]
% I want to have something like this
ans(:,:,1) = [1 2
5 6]
ans(:,:,2) = [9 10
13 14]
ans(:,:,3) = [3 4
7 8]
ans(:,:,4) = [11 12
15 16]

回答(1 个)

darova
darova 2021-4-1

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by