find the multiple max values
이전 댓글 표시
I have a matrix
8 23 44 19
44 5 62 1
7 6 12 33
6 55 24 8
and I want to find 3 largest values(reserve duplicate matches),and then make the other be 0
just like
0 0 44 0
44 0 62 0
0 0 0 0
0 55 0 0
I have read some book ,but I still have no idea
help me plz
댓글 수: 3
Aditya Verma
2020년 6월 16일
Hello, could you please specify what you have tried until now, and in which part you are facing problem.
chung yen chang
2020년 6월 18일
chung yen chang
2020년 6월 18일
채택된 답변
추가 답변 (1개)
Stephen23
2020년 6월 16일
Where M is your matrix:
>> U = unique(M(:));
>> X = ismember(M,U(end-2:end));
>> M(~X) = 0
M =
0 0 44 0
44 0 62 0
0 0 0 0
0 55 0 0
댓글 수: 3
chung yen chang
2020년 6월 18일
"Thanks, bro this answer can work very well"
Note my answer actually gives the output that you asked for (unlike the answer that you accepted):
>> M = [4,4,4;4,4,4;3,2,1]
M =
4 4 4
4 4 4
3 2 1
>> U = unique(M(:));
>> X = ismember(M,U(end-2:end));
>> M(~X) = 0
M =
4 4 4
4 4 4
3 2 0
madhan ravi
2020년 6월 18일
However maxk(...) gives the right answer xD, but i do agree the loophole.
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!