How to find index of maximum value/s of a matrix?

4 ビュー (過去 30 日間)
Janine Lim
Janine Lim 2015 年 5 月 1 日
編集済み: Stephen23 2015 年 5 月 1 日
I have a 256-by-1 matrix, let's name it 'Matrix1'. I used sort to arrange the elements in descending order.
maxes = sort(Matrix1, 'descend');
How can I get the corresponding indices (from Matrix1) of that first five maximum values outputted by maxes?
EDIT: I also accept the sort method. I've already tried that. However, is there a chance this can be solved using both sort and find function too?
  1 件のコメント
Stephen23
Stephen23 2015 年 5 月 1 日
The sort documentation is a good place to start:
and look for the second output: these are the indices.

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 5 月 1 日
編集済み: Azzi Abdelmalek 2015 年 5 月 1 日
a=[2 3 1 5 6 4 0 5 2]
[out,indices]=sort(a,'descend')
  2 件のコメント
Janine Lim
Janine Lim 2015 年 5 月 1 日
編集済み: Janine Lim 2015 年 5 月 1 日
Is there a chance those indices could be retrieved using find? Another instruction was we have to use sort and then find.
Stephen23
Stephen23 2015 年 5 月 1 日
編集済み: Stephen23 2015 年 5 月 1 日
Try it and find out if it works.
Think about how it might work: how could it be used to find indices?
Your computer will not catch fire if it does not work, so why not try a few different code variations and see what happens? Read the find documentation, and consider how this could be used to locate indices... or perhaps not. You might learn more than just asking for the answer when you actually understand what find is doing, and for that nothing beats seeing it for yourself.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by