Filter löschen
Filter löschen

To find the location of maximum number

3 Ansichten (letzte 30 Tage)
fyza affandi
fyza affandi am 28 Dez. 2018
Kommentiert: Star Strider am 28 Dez. 2018
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

Akzeptierte Antwort

Star Strider
Star Strider am 28 Dez. 2018
Use the find (link) funciton:
a= [1 2 5 7 7 5 3];
allmaxidx = find(a == max(a(:)))
producing:
allmaxidx =
4 5
  2 Kommentare
fyza affandi
fyza affandi am 28 Dez. 2018
Thank you :)
Star Strider
Star Strider am 28 Dez. 2018
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by