To find the location of maximum number

조회 수: 1 (최근 30일)
fyza affandi
fyza affandi 2018년 12월 28일
댓글: Star Strider 2018년 12월 28일
I have a array
a= [1 2 5 7 7 5 3]
I want to get the location of the maximum number(for this example =7)
I use this code
[x,y]=max(t1)
x=
7
y=
4
the code only shows one location. What can I change in the code two get 2 location which is 4 and 5 instead of 4?
y =
4
5

채택된 답변

Star Strider
Star Strider 2018년 12월 28일
Use the find (link) funciton:
a= [1 2 5 7 7 5 3];
allmaxidx = find(a == max(a(:)))
producing:
allmaxidx =
4 5
  댓글 수: 2
fyza affandi
fyza affandi 2018년 12월 28일
Thank you :)
Star Strider
Star Strider 2018년 12월 28일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by