Matlab - Transpose a 3D matrix only in the third dimension

坚强是说给别人听的谎言 提交于 2019-12-01 02:29:18

问题


I have a 3 x 3 x 2 matrix, for example :

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

M(:,:,2) =
    10    11    12
    13    14    15
    16    17    18

and I would like to transpose each M(:,:,i), I mean I would like to have :

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

M(:,:,2) =
    10    13    16
    11    14    17
    12    15    18

How is it possible to do this without loops ? Thank you very much !


回答1:


That's what permute does:

result = permute(M, [2 1 3]); %// swap dimensions 1 and 2


来源:https://stackoverflow.com/questions/27301188/matlab-transpose-a-3d-matrix-only-in-the-third-dimension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!