Hi i need help trying to extract the name of a value associated to an array

2 ビュー (過去 30 日間)
Dylan Watt
Dylan Watt 2020 年 5 月 11 日
編集済み: Stephen23 2020 年 5 月 14 日
This is the array
criterion = [Tsai_Hill, Tsai_Wu, Hoffman, Fischer, Malmeister, Marin, Ashkenazi, Cowin];
[r,t] = max(criterion);
All of the elements in the array have a value and i know how to find the max value and at what position it is, but is there a way to use the index value to get the name of the element that is the max value.
i.e. if Tsai_Hill is the max value, it will give me the value and then instead of giving me the index, it gives me Tsai_hill?
  1 件のコメント
Stephen23
Stephen23 2020 年 5 月 14 日
編集済み: Stephen23 2020 年 5 月 14 日
Rather than forcing meta-data into variable names, just use a table: it will make your code simpler.

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

回答 (1 件)

Mahesh Taparia
Mahesh Taparia 2020 年 5 月 14 日
Hi
You can create a separate string array with the same elements in the same order and access those with corresponding max index. For example consider the below code:
criterionStr = ["Tsai_Hill", "Tsai_Wu", "Hoffman", "Fischer", "Malmeister", "Marin", "Ashkenazi", "Cowi"];
criterion = [Tsai_Hill, Tsai_Wu, Hoffman, Fischer, Malmeister, Marin, Ashkenazi, Cowin];
[r,t] = max(criterion);
personName=criterionStr(t) %%% It will give the names

カテゴリ

Help Center および File ExchangeAntenna and Array Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by