Finding the last maximum value in a vector

Hi,
"max" gives the maximum value of a matrix in a row vector.
This vector contains all the maximum values in the respective column.
if i use [V,X]= max(max(A)) this will give me the largest value of the vector in the corresponding X.
Definitely in the vector there are many values which are equal to max(max(A))
I want to know that how can i know the last index that has this value in the vector.
Pls guide me.
Thanks

 採用された回答

ME
ME 2019 年 11 月 4 日

0 投票

I think this should do it for you:
idx = max(find(A==max(max(A))))

8 件のコメント

Guillaume
Guillaume 2019 年 11 月 4 日
max(max(A)), assuming a 2D matrix, is probably faster as:
max(A(:))
or since R2018b, even faster as
max(A, [], 'all')
ME
ME 2019 年 11 月 4 日
Fair enough! These are good suggestions!
Ghulam
Ghulam 2019 年 11 月 4 日
Really thankful to you ME.
It worked
Can you please also answer my This Question and This one.
Ghulam
Ghulam 2019 年 11 月 4 日
Is there any other method too for finding it.
The suggestion tells.
find.png
Guillaume
Guillaume 2019 年 11 月 4 日
編集済み: Guillaume 2019 年 11 月 4 日
Follow its suggestion then:
X = find(A == max(A(:)), 1, 'last');
I recommend you don't use Max as a variable name. Differentiating variables and function name just by a difference in case is asking for trouble. You can be sure that one time you'll mistype max instead of Max and waste time hunting the bug.
ME
ME 2019 年 11 月 4 日
As in the suggestion, you could use:
idx = find(A==max(max(A)),1,'last')
instead. You'd also be ale to use the suggestions of Guillaume to speed this up a bit further.
Ghulam
Ghulam 2019 年 11 月 4 日
Regarding the same question of finding the index of max value.
If i say that i want to find out at which index after this index (i mean the above we calculated) the value become x
Ghulam
Ghulam 2019 年 11 月 4 日
I found it.
max(find(Max>round(mean(Max))))

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

質問済み:

2019 年 11 月 4 日

コメント済み:

2019 年 11 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by