필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Sami ullah
Sami ullah 2020년 7월 26일
댓글: Cris LaPierre 2020년 7월 26일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 7월 26일
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
Cris LaPierre
Cris LaPierre 2020년 7월 26일
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)).

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

추가 답변 (1개)

Sami ullah
Sami ullah 2020년 7월 26일
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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by