Create an array of the row and column values for the indices of an array.
This is typically performed using [r c]=ind2sub(size(matrix), index).
The ind2sub output can be vectorized.
Create an index row/col array(irc) where index is the row of the irc array, column 1 is the array row and column 2 is the array column.
m=[0 0; 0 1] has four indices thus producing a four row and two column irc array.
irc= [1 1 2 1 1 2 2 2]
Index 4's row is irc(4,1)=2 and its col is irc(4,2)=2. The values of m are irrelevant.
Puzzle, and initial tightest solution, inspired by code implemented by Alfonso Nieto-Castanon.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers48
Suggested Problems
-
Find the sum of all the numbers of the input vector
54301 Solvers
-
2721 Solvers
-
Remove the two elements next to NaN value
706 Solvers
-
Set the array elements whose value is 13 to 0
1441 Solvers
-
I've got the power! (Inspired by Project Euler problem 29)
143 Solvers
More from this Author305
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!