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

20.9% Correct | 79.1% Incorrect
Last Solution submitted on Aug 27, 2024

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

More from this Author31

Community Treasure Hunt

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

Start Hunting!