how to return column index in matrix
Show older comments
how i return column number when i have matrix 300 on 3 when the constrain is: idx(i) = number of the column with the min number in the row, example:
8 1 6
3 5 7
4 9 2
idx(1) = 2
idx(2) = 1
idx(3) = 3
:)
Accepted Answer
More Answers (1)
Star Strider
on 9 Jan 2018
Use the min function with 2 outputs:
M = [8 1 6
3 5 7
4 9 2];
[~,idx] = min(M,[],2)
idx =
2
1
3
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!