how to avoid NaN

  • Follow


Hi,

By using sum function I want to sum up the values in a vector, the results should be 14,532,000 but I get NaN. How can I avoid to get NaN? How can I get 14,532,000 instead of NaN. The vector can be shown, however I cannot get result of summation.

Thank you in advance.

Regards,

Ozge
0
Reply Ozge 4/29/2010 5:50:21 AM

x = [4 5 6 NaN 10 3];
sum(x(~isnan(x)))  % Compare to sum(x)
0
Reply Matt 4/29/2010 6:05:23 AM


"Ozge Taskan" <lordgy@yahoo.com> wrote in message <hrb6mt$5jn$1@fred.mathworks.com>...
> Hi,
> 
> By using sum function I want to sum up the values in a vector, the results should be 14,532,000 but I get NaN. How can I avoid to get NaN? How can I get 14,532,000 instead of NaN. The vector can be shown, however I cannot get result of summation.
> 
> Thank you in advance.
> 
> Regards,
> 
> Ozge

in addition - and - if(f) you own the stats tbx

     help nanmean;     % <- and siblings...

us
0
Reply us 4/29/2010 6:29:31 AM

"Matt Fig" <spamanon@yahoo.com> wrote in message <hrb7j3$112$1@fred.mathworks.com>...
> x = [4 5 6 NaN 10 3];
> sum(x(~isnan(x)))  % Compare to sum(x)

Hi,

Thank you for your interest. But I have no NaN value in my vector. I get NaN as a result, however when I export my vector to Excel and sum the values in the vector I get 14,532,000. The point that I do not understand is why I get NaN instead of 14,532,000 from Matlab. I want to do something and get the exact result instead of NaN. Thank you.

Regards, 

Ozge
0
Reply Ozge 4/29/2010 6:32:09 AM

O.k., so what do you get for this:

any(~isfinite(x))  % replace x with your vector.
0
Reply Matt 4/29/2010 7:00:23 AM

4 Replies
517 Views

(page loaded in 2.352 seconds)

Similiar Articles:













7/23/2012 1:57:23 AM


Reply: