Using the max function to recieve two outputs

11 ビュー (過去 30 日間)
Nathan Freitas
Nathan Freitas 2015 年 9 月 23 日
編集済み: Stephen23 2015 年 9 月 23 日
Hey, I have three vectors with 5 elements in each. Let them be x, y and t. I want to find the maximum value in x, when y >= 10. I've done this with:
x = [1 3 8 9 11]
y = [10 10.1 10.5 9 8]
t = [0.6 0.7 1 1.2 1.4]
d = max(x(find(y >= 10)))
This correctly returns the max value, I now what to find the value of t that corresponds to the max value in x. For example d = 8, and is the 3rd element in x, how do I automate the proccess of finding the 3rd element in t, which is 1.
Apperently I can use max to recieve two outputs, which can be both x and t]
Thanks!

採用された回答

Stephen23
Stephen23 2015 年 9 月 23 日
編集済み: Stephen23 2015 年 9 月 23 日
You need to use the second output of max, which is an index. Here are two ways of doing this:
With find
idy = find(y>=10)
[d,idx] = max(x(idy))
t(idy(idx))
With temporary variable
idy = y>=10;
tmp = t(idy);
[d,idx] = max(x(idy))
tmp(idx)
  1 件のコメント
Nathan Freitas
Nathan Freitas 2015 年 9 月 23 日
Thank you very much!
+1 for extra help

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by