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 Solvers15
Suggested Problems
-
84 Solvers
-
365 Solvers
-
Replace multiples of 5 with NaN
472 Solvers
-
String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values
2081 Solvers
-
calculate the length of matrix
2643 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!