listing only the first index

조회 수: 5 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2015년 2월 10일
답변: Hikaru 2015년 2월 10일
I have a matrix
A= [ 1 3 5 7 33 23 44 55 55]
I want to find the index of the maximum value, so I used this line
A= find( A == max(A(:)))
However this displays both indices (8 & 9) since they both have a value of 55, however I want it to only list the first index, 8. How would I go about that?
Thanks

채택된 답변

Hikaru
Hikaru 2015년 2월 10일
The function max alone is sufficient, you don't have to use find for this sort of problem.
[Y,I] = max(A)
The variable I will return the index of the first maximum value.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by