Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matrix manipulation

Subject: matrix manipulation

From: Wendy

Date: 9 Apr, 2010 11:23:20

Message: 1 of 3

Hi all,

I am a very simple question, but I am not sure what function that I shall use. I have a matrix as follows,

a =

   NaN 4 NaN
     3 2 1

How can I count the number of 'NaN' in the matrix? Can I change the 'NaN' to zeros at once? I tried to a(a==NaN)=0, but it does not work.

Thank you,
Wendy

Subject: matrix manipulation

From: Wendy

Date: 9 Apr, 2010 11:48:07

Message: 2 of 3

sorry, solved.
Wendy

"Wendy " <wlq121@gmail.com> wrote in message <hpn2n8$17b$1@fred.mathworks.com>...
> Hi all,
>
> I am a very simple question, but I am not sure what function that I shall use. I have a matrix as follows,
>
> a =
>
> NaN 4 NaN
> 3 2 1
>
> How can I count the number of 'NaN' in the matrix? Can I change the 'NaN' to zeros at once? I tried to a(a==NaN)=0, but it does not work.
>
> Thank you,
> Wendy

Subject: matrix manipulation

From: Wolfgang Schwanghart

Date: 9 Apr, 2010 11:53:08

Message: 3 of 3

Wendy,

"equal to" doesn't work for nan. Look at the function isnan.

I = isnan(a);
% nr of nans
nnz(I)

% replace nans with zeros
a(I) = 0;

Best regards,
Wolfgang

 

"Wendy " <wlq121@gmail.com> wrote in message <hpn2n8$17b$1@fred.mathworks.com>...
> Hi all,
>
> I am a very simple question, but I am not sure what function that I shall use. I have a matrix as follows,
>
> a =
>
> NaN 4 NaN
> 3 2 1
>
> How can I count the number of 'NaN' in the matrix? Can I change the 'NaN' to zeros at once? I tried to a(a==NaN)=0, but it does not work.
>
> Thank you,
> Wendy

Tags for this Thread

No tags are associated with this thread.

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.

Contact us