Find the first position of maximum value in a Matrix

Hello everyone,
Suppose there can be the max value at more than one location, how can I catch the first max value.
A = [6;7;21;4;9;21;5;1];
max(A(:))
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue)
ans =
21
rowsOfMaxes =
3
6
colsOfMaxes =
1
1
Then I want it to be:
ans =
21
rowsOfMaxes =
3
colsOfMaxes =
1
Can anyone please help me?

댓글 수: 1

I'm confused as to why you are referring to rows and columns, when the original input is a vector, not a matrix.

댓글을 달려면 로그인하십시오.

 채택된 답변

José-Luis
José-Luis 2014년 5월 5일
편집: José-Luis 2014년 5월 5일
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue,1,'first')
Please accept an answer if it helped you.

댓글 수: 2

Thanks Jose. It was very helpful.
if i want to find the 3rd max value as '9' and its position...what shall i do?????

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

질문:

Moe
2014년 5월 5일

댓글:

2014년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by