MATLAB Answers

0

replace values with nans

Asked by Leela Sai Krishna on 18 Mar 2019
Latest activity Commented on by Leela Sai Krishna on 18 Mar 2019
I have a matrix data. i applied a condition and i get the idx. i want to replace that idx values with Nans.
plz suggest the process for this.
Thanks....

  0 Comments

Sign in to comment.

Tags

2 Answers

madhan ravi
Answer by madhan ravi
on 18 Mar 2019
 Accepted Answer

data(idx)=NaN

  1 Comment

thanks it works.
actually i want to replace values in matrices with nans whose idx is 1

Sign in to comment.


Answer by Jos (10584)
on 18 Mar 2019

Take a look at logical indexing or the function ind2sub
M = randi(10,8,6)
% use indices of elements for which condition is true
idx = find(M > 8)
M(sub2ind(size(M), idx)) = NaN
% use logical indexing (easier in many cases)
M(M < 3) = 999

  0 Comments

Sign in to comment.