Problem 54685. Matrix Transposition
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
Joel Hottinger
on 26 May 2022
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];
Joel Hottinger
on 26 May 2022
Also tests 5 and 6 do not work
one is missing a " ] " and the other has some function that does not work
Dyuman Joshi
on 26 May 2022
@Joel,
Apologies for the error, they have been corrected.
Your answer has been re-scored. Do rate the question!
Solution Comments
Show commentsProblem Recent Solvers12
Suggested Problems
-
6078 Solvers
-
How to find the position of an element in a vector without using the find function
2804 Solvers
-
Change the sign of even index entries of the reversed vector
626 Solvers
-
Convert a Cell Array into an Array
2163 Solvers
-
Area of an equilateral triangle
6751 Solvers
More from this Author43
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!