COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

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

• Email
• 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

See related articles to this posting

```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
575 Views

Similar Articles

12/7/2013 5:33:47 PM
page loaded in 4897 ms. (0)

 Reply:

Similar Artilces: