From: Wendy on
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
From: Wendy on
sorry, solved.
Wendy

"Wendy " <wlq121(a)gmail.com> wrote in message <hpn2n8$17b$1(a)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
From: Wolfgang Schwanghart on
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(a)gmail.com> wrote in message <hpn2n8$17b$1(a)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