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

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

From: Priom Rahman

Date: 30 Jul, 2010 22:47:06

Message: 1 of 4

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.

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

From: ImageAnalyst

Date: 30 Jul, 2010 22:55:54

Message: 2 of 4

x(x==0)=nan

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

From: Walter Roberson

Date: 30 Jul, 2010 22:55:48

Message: 3 of 4

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

x(~x)=nan; % :p

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

From: Priom Rahman

Date: 30 Jul, 2010 23:02:06

Message: 4 of 4

Brilliant thanks !!!!!!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
find replace Priom Rahman 30 Jul, 2010 18:49:05
turn 0s to nan Priom Rahman 30 Jul, 2010 18:49:05
rssFeed for this Thread

Contact us at files@mathworks.com