Suppose I have a matrix
A=[2 3 4; 6 1 2]
I want to find 2 largest elements and make all the other elements zero. In this case A finally becomes
A=[0 0 4; 6 0 0]
Suppose I have a matrix
A=[2 3 4; 6 1 2]
I want to find 2 largest elements and make all the other elements zero. In this case A finally becomes
A=[0 0 4; 6 0 0]
Your line of action should be:
A
.A = [2 3 4; 6 1 2];
[Y, idx] = sort(A(:), 'descend')
A(idx(3:end)) = 0
This should result in:
A =
0 0 4
6 0 0
>> A=[2 3 4; 6 1 2]
A =
2 3 4
6 1 2
>> [~,idx] = sort(A(:), 'descend');
>> A(idx(3:end))=0
A =
0 0 4
6 0 0