How can I rotate a part of a matrix
Show older comments
Hi there,
I have a 4D images (dimensions [156 192 26 42]). I would like to rotate only the last 20 volumes of my 4D matrix and keep the first as it is.
I tried the following:
rotated_matrix=original_matrix;
rotated_matrix = rot90(original_matrix(:,:,:,23:42));
The rotated_matrix has been rotated but it has dimensions [192 156 26 20]. Basically it contains the volumes that have been rotated.
How can I rotate only the volume in the last 20 places and keep the first 22 as they are?
Answers (1)
Ameer Hamza
on 24 Sep 2020
Try something like this
rotated_matrix = original_matrix(:,:,:,[1:20 42:-1:21]);
6 Comments
DM
on 24 Sep 2020
Ameer Hamza
on 24 Sep 2020
Ok. You wanted to rotate the last 20 only. There will be a minor modification. Does the following work?
rotated_matrix = original_matrix(:,:,:,[1:22 42:-1:23]);
DM
on 24 Sep 2020
Ameer Hamza
on 24 Sep 2020
It reverse the order of last 20 elements in the 4th dimension. The other elements remain unchanged.
DM
on 24 Sep 2020
Ameer Hamza
on 24 Sep 2020
Ok. I get it know. Following will work for this case
original_matrix(:,:,:,end-19:end) = rotated_matrix
Categories
Find more on Image Processing Toolbox 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!