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
:)

 채택된 답변

James Tursa
James Tursa 2018년 1월 9일

2 개 추천

x = your original matrix
[~,idx] = min(x,[],2);

추가 답변 (1개)

Star Strider
Star Strider 2018년 1월 9일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2018년 1월 9일

답변:

2018년 1월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by