Matrix Transposition - MATLAB Cody - MATLAB Central

Problem 54685. Matrix Transposition

Difficulty:Rate
Given a matrix and an index, perform matrix transposition as follows -
Replace non-corner value of ith ring from outside, with the adjacent values of the next ring.
x = [1 2 3 4
5 6 7 8
1 2 3 4];
i = 1; %operate on outermost ring of matrix
y = [1 6 7 4
6 6 7 7
1 6 7 4];
x = [4 1 4 6 0 5
1 4 9 6 9 9
0 2 8 4 9 1
5 8 4 0 6 5
9 2 7 3 6 2
8 0 6 3 2 7
3 1 9 6 2 2];
i = 2; %operate on second ring of matrix
y = [4 1 4 6 0 5
1 4 8 4 9 9
0 8 8 4 4 1
5 4 4 0 0 5
9 7 7 3 3 2
8 0 7 3 2 7
3 1 9 6 2 2];
x = [6 5 1 0 7 4 2
3 6 9 4 6 9 5
7 9 3 3 6 3 3
2 4 5 2 3 3 5
7 4 0 1 4 5 1
7 8 5 9 5 1 4
9 2 5 6 7 6 8];
i = 3; %operate on third ring of matrix
y = [6 5 1 0 7 4 2
3 6 9 4 6 9 5
7 9 3 2 6 3 3
2 4 2 2 2 3 5
7 4 0 2 4 5 1
7 8 5 9 5 1 4
9 2 5 6 7 6 8];

Solution Stats

85.71% Correct | 14.29% Incorrect
Last Solution submitted on May 04, 2025

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers11

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!