How to find the multiple max values
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
say like I have this 2D matrix
11 2 3 6
5 6 9 8
9 55 11 12
80 14 15 16
17 97 35 20
21 22 23 27
and I want to find the 4 largest values in column 3. How do I do that? *I did read some of the other posts but I can't seem to find anything conclusive.
採用された回答
Walter Roberson
2017 年 2 月 22 日
dvals = sort(YourMatrix(:,3), 'descend');
largest4 = dvals(1:4);
8 件のコメント
Anonymous Matrix
2017 年 2 月 22 日
great! thanks! but just one more question if you don't mind. How do I get the indices? (i'm sorry if the answer is insanely obvious but i'm kinda sick so my brain isn't functioning really well right now)
Walter Roberson
2017 年 2 月 22 日
[dvals, dindex] = sort(YourMatrix(:,3), 'descend');
largest4 = dvals(1:4);
index_of_largest4 = dindex(1:4);
jaah navi
2019 年 3 月 29 日
編集済み: Walter Roberson
2019 年 5 月 29 日
With respect to the matrix
[11 2 3 6;
5 6 9 8;
9 55 11 12;
80 14 15 16;
17 97 35 20;
21 22 23 27]
how to frame the matrix such that it should display with two maximum values of each column and the other values to be zero.
lets say the output should be in the following manner
[0 0 0 0;
0 0 0 0;
0 55 0 0;
80 0 0 0;
0 97 35 0;
21 0 23 27]
Could you please help me on this.
Walter Roberson
2019 年 3 月 29 日
What should be done if there are duplicate matches? Three all the same, or one max and two copies of second best?
jaah navi
2019 年 5 月 29 日
with respect to the matrix
11 2 3 6
5 6 9 8
9 55 11 12
80 14 15 16
17 97 35 20
21 22 23 27
how to find the largest four values in all columns.
Guillaume
2019 年 5 月 29 日
Since this old answer has been revived, note that since R2017b you can use maxk which may or may not be faster than sorting the whole array/column. See also topkrows (R2016b or later) which may have been the ultimate goal here.
[largest4, indexoflargest4] = maxk(Yourmatrix(:, 3), 4);
%or
[largest4rows, indices] = topkrows(Yourmatrix, 4, 3);
@Jaah navi, as usual, when wanting to operate on the whole matrix reshape it into a single column with (:).
Walter Roberson
2019 年 5 月 29 日
What should be done if there are duplicate matches? Five all the same, or one max and four copies of second best, or one max and one second best and three copies of the third best, and so on? Your question contains no information about how you want to handle ties.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
