Matlab - 仅在第三维中转换3D矩阵

use*_*336 7 arrays matlab transpose multidimensional-array

我有一个3 x 3 x 2矩阵,例如:

M(:,:,1) =
     1     2     3
     4     5     6
     7     8     9

M(:,:,2) =
    10    11    12
    13    14    15
    16    17    18
Run Code Online (Sandbox Code Playgroud)

我想转移每一个M(:,:,i),我的意思是我希望:

M(:,:,1) =
     1     4     7
     2     5     8
     3     6     9

M(:,:,2) =
    10    13    16
    11    14    17
    12    15    18
Run Code Online (Sandbox Code Playgroud)

如何在没有循环的情况下做到这一点?非常感谢你 !

Lui*_*ndo 11

这是做什么的permute:

result = permute(M, [2 1 3]); %// swap dimensions 1 and 2
Run Code Online (Sandbox Code Playgroud)