MATLAB Answers

0

Replace largest elements in matrix with NaN

Asked by Meg Cullen on 14 May 2019
Latest activity Answered by Kevin Phung on 14 May 2019
I would like to replace the n largest numbers in first column with NaN in a matrix.
For example for value n = 3 for matrix A output will be B :
A =
17 2
5 68
79 28
900 17
77 63
90 87
B =
17 2
5 68
NaN 28
NaN 17
77 63
NaN 87
What will be the code for this?

  0 Comments

Sign in to comment.

1 Answer

回答者: Kevin Phung
2019 年 5 月 14 日
 採用された回答

A =[17 2
5 68
79 28
900 17
77 63
90 87];
n = 3;
elem = sort(A(:,1),'d');
elem = elem(1:n);
A(ismember(A(:,1),elem)) = NaN;

  0 Comments

Sign in to comment.