anyone can help me how to find the oldest person in a room?

7 Ansichten (letzte 30 Tage)
anyone can help me how to find the oldest person in a room?
i have write code :
old_name=name(max(age))
first access the max age the pass it to the name to get the name of oldest man.
is it true or not??
please guide me
Thanks in advance

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 26 Jul. 2020
No. This returns the persons age. You want the index, so you'll have to do this in 2 steps. See the documentation for max to see how to get the index of the max value.
  1 Kommentar
Cris LaPierre
Cris LaPierre am 26 Jul. 2020
One thing to be aware of: if there are multiple people with max age, this will return the first one only. You can use logical indexing to extract all entries that match your condition
name(age==max(age)).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sami ullah
Sami ullah am 26 Jul. 2020
i have solved this problem successfully
here is solution:
function old_name = find_max_age(name,age)
[~,Id]=max(age)
old_name=name(Id)
end

Kategorien

Mehr zu Get Started with MATLAB 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