フィルターのクリア

How to find rows with maximum number

1 回表示 (過去 30 日間)
Maryam Hamrahi
Maryam Hamrahi 2016 年 8 月 7 日
コメント済み: Star Strider 2016 年 8 月 7 日
I have a matrix with n rows and 1 column. I would like to find rows which has the maximum number of rows. Then, replace zero in the other rows.
For instance: I have matrix A and I would like to produce matrix B.
A=
5
2
2
4
3
2
B=
0
2
2
0
0
2

採用された回答

Star Strider
Star Strider 2016 年 8 月 7 日
This works:
A = [5
2
2
4
3
2];
[Au,ia,ic] = unique(A, 'stable');
h = accumarray(ic, 1);
B = A;
B(ic~=Au(h==max(h))) = 0
B =
0
2
2
0
0
2
  6 件のコメント
Maryam Hamrahi
Maryam Hamrahi 2016 年 8 月 7 日
Sorry, it was my mistake. I have to correct it myself. I am thankful for your help.
Star Strider
Star Strider 2016 年 8 月 7 日
My pleasure.

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

その他の回答 (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