Finding a specific index while labeling it with another

1 回表示 (過去 30 日間)
Evan Bakalars
Evan Bakalars 2021 年 2 月 19 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 19 日
If I have to find which person has the youngest age by labeling which person they are, how would I do that?
The array looks like this: AgeArray=[person;age] ---> AgeArray=[1, 2, 3, 4, 5; 12, 46, 84, 8, 23]
The left side is person 1, person 2, person 3, and so on, and the right side is the age, person 1 is 12 years old, person 2 is 46 years old, etc.
If I used the min(age) that will yield 8, which is person 4, but I am looking for the function to have the answer come back as person 4.
Thank you and sorry if it is confusing.
  1 件のコメント
Stephen23
Stephen23 2021 年 2 月 19 日
編集済み: Stephen23 2021 年 2 月 19 日
M = [1, 2, 3, 4, 5; 12, 46, 84, 8, 23]
M = 2×5
1 2 3 4 5 12 46 84 8 23
[~,X] = min(M(2,:));
P = M(1,X)
P = 4

サインインしてコメントする。

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 19 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 19 日
AgeArray=[1, 2, 3, 4, 5; 12, 46, 84, 8, 23]
per=AgeArray(1,:);
min_per=per(min(AgeArray(2,:))==AgeArray(2,:))
Result:
min_per =
4
Considering AgeArray as the following format
AgeArray =
1 2 3 4 5
12 46 84 8 23
If the Given data in this format
AgeArray =
1 12
2 46
3 84
4 8
5 23
Then
per=AgeArray(:,1);
min_per=per(min(AgeArray(:,2))==AgeArray(:,2))
Result:
min_per =
4

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by