필터 지우기
필터 지우기

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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by