Problem 54035. Matrix Rotation
You are given a 2D matrix of dimension [m,n] and a positive integer r. You have to rotate the matrix r times and print the resultant matrix. Rotation should be performed in alternating layers of matrix
Example (for r=1)
Start with rotating the outer layer counter-clockwise, reverse the direction with each layer.
y = [1 2 3 4 5 6 [2 3 4 5 6 12
7 8 9 10 11 12 1 14 8 9 10 18
13 14 15 16 17 18 -> 7 20 16 22 11 24
19 20 21 22 23 24 -> 13 26 15 21 17 30
25 26 27 28 29 30 19 27 28 29 23 36
31 32 33 34 35 36] 25 31 32 33 34 35]
y = [7 8 9 10 [8 9 10 11
6 1 2 11 -> 7 4 1 12
5 4 3 12 -> 6 3 2 13
16 15 14 13] 5 16 15 14]
y = ['abcde' ['bcdej'
'fghij' -> 'amghp'
'lmnop' -> 'fnoit'
'pqrst'] 'lpqrs']
See test suite for further clarity.
Solution Stats
Problem Comments
-
8 Comments
Show
5 older comments
William
on 25 Feb 2022
Yes, I agree. Those two are still comparing to matrices that are different than the correct results that I included in my previous comment.
Dyuman Joshi
on 26 Feb 2022
William and Tim, apologies for the fiasco. The test suite has been corrected completely.
Tim, your answer has been rescored and accepted. Do rate the question!
William
on 26 Feb 2022
It works! Thanks Dyuman.
Solution Comments
Show commentsProblem Recent Solvers14
Suggested Problems
-
415 Solvers
-
715 Solvers
-
423 Solvers
-
150 Solvers
-
Combined Ages 1 - Symmetric, n = 3
263 Solvers
More from this Author31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!