Problem 2493. Must be in the front row...
You are given a matrix followed by a single number. Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix. For example, if you start with the magic(4) matrix:
16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1
and the number 6, your output should be:
6 12 9 7 15 1 4 14 3 13 16 2 10 8 5 11
If there is more than one instance of the number, use the one in the leftmost column. If there is more than one in that column, use the one in the uppermost row. If your input is a modified magic(4)
16 2 3 13 6 11 10 8 9 7 6 12 6 14 15 1
and you need to put 6 in the upper left corner, your output should be:
6 11 10 8 9 7 6 12 6 14 15 1 16 2 3 13
If the input number isn't in the matrix, return the original matrix. Good luck!
Solution Stats
Problem Comments
-
1 Comment
This problem is exactly the same as the next one, "Go to the head of the class!"
Solution Comments
Show commentsGroup

Matrix Manipulation I
- 16 Problems
- 98 Finishers
- Remove the air bubbles
- Remove NaN ?
- N-Dimensional Array Slice
- Back to basics 21 - Matrix replicating
- Back to basics 23 - Triangular matrix
- Make an awesome ramp for a tiny motorcycle stuntman
- Flip the main diagonal of a matrix
- surrounded matrix
- Some Assembly Required
- Set some matrix elements to zero
- Matrix with different incremental runs
- Removing rows from a matrix is easy - but what about inserting rows?
- Rotate input square matrix 90 degrees CCW without rot90
- Permute diagonal and antidiagonal
- Operate on matrices of unequal, yet similar, size
- Reverse the elements of an array
Problem Recent Solvers135
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!