How do you find all the 0's in a matrix and replace with NaN

  • Follow


Could someone tell me how to search for all the zero's in a martix and then replace it wirh NaN ?

say:
x = [1 1 1 0;  1 1 0 0; 0 0 0 0; 1 1 0 1; 0 0  1 1]

x =

     1     1     1     0
     1     1     0     0
     0     0     0     0
     1     1     0     1
     0     0     1     1

I can find the 0 using 

 find(x == 0)

ans =

     3
     5
     8
    10
    12
    13
    14
    16
    17
    18

But how do I replace these values ?

I'm sorry if similar questions have been answered, but I could only find examples of replacing NaNs with numbers or integers.
0
Reply Priom 7/30/2010 10:47:06 PM

ImageAnalyst wrote:
> x(x==0)=nan

x(~x)=nan;    % :p
0
Reply Walter 7/30/2010 10:55:48 PM


x(x==0)=nan
0
Reply ImageAnalyst 7/30/2010 10:55:54 PM

Brilliant thanks !!!!!!
0
Reply Priom 7/30/2010 11:02:06 PM

3 Replies
459 Views

(page loaded in 0.083 seconds)

Similiar Articles:













7/23/2012 9:12:54 PM


Reply: