# how to rotate a 3d matrix ?

4 views (last 30 days)
Rabih Sokhen on 19 Sep 2022
Commented: Matt J on 19 Sep 2022
hy guys
i would like to rotate a 3*3 array
suppose i have A=rand(5,4,3)
i would like to rotate it in a way were A now is (4,5,3)
best regards

Matt J on 19 Sep 2022
Edited: Matt J on 19 Sep 2022
permute(A,[2,1,3])
or
pagetranspose(A)
##### 2 CommentsShowHide 1 older comment
Matt J on 19 Sep 2022
Yes, the second argument to the permute command lets you specify exactly how you want the axes reordered.

Matt J on 19 Sep 2022
Edited: Matt J on 19 Sep 2022
A=randi(50,5,4,3)
A =
A(:,:,1) = 20 45 46 13 13 33 29 39 49 39 2 7 19 9 40 20 46 3 17 13 A(:,:,2) = 4 19 6 6 23 29 49 49 36 3 14 48 50 30 34 6 43 1 28 41 A(:,:,3) = 50 14 38 31 16 18 30 3 15 23 7 28 7 14 47 19 19 3 49 3
rot90(A) %or imrotate(A,90)
ans =
ans(:,:,1) = 13 39 7 20 13 46 29 2 40 17 45 33 39 9 3 20 13 49 19 46 ans(:,:,2) = 6 49 48 6 41 6 49 14 34 28 19 29 3 30 1 4 23 36 50 43 ans(:,:,3) = 31 3 28 19 3 38 30 7 47 49 14 18 23 14 3 50 16 15 7 19

### Categories

Find more on Matrices and Arrays in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!