Reshaping a matrix in particular order
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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]
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!