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
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers12
Suggested Problems
-
538 Solvers
-
Make a random, non-repeating vector.
11184 Solvers
-
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
2037 Solvers
-
Check that number is whole number
5193 Solvers
-
1252 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Why is your first example have an answer of
y = [1 6 7 4
5 6 7 7
1 6 7 4];
and not
y = [1 6 7 4
6 6 7 7
1 6 7 4];
Also tests 5 and 6 do not work
one is missing a " ] " and the other has some function that does not work
@Joel,
Apologies for the error, they have been corrected.
Your answer has been re-scored. Do rate the question!