From: Ozge Taskan on
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
From: Matt Fig on
x = [4 5 6 NaN 10 3];
sum(x(~isnan(x))) % Compare to sum(x)
From: us on
"Ozge Taskan" <lordgy(a)yahoo.com> wrote in message <hrb6mt$5jn$1(a)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
From: Ozge Taskan on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hrb7j3$112$1(a)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
From: Matt Fig on
O.k., so what do you get for this:

any(~isfinite(x)) % replace x with your vector.
 | 
Pages: 1
Prev: speed of fread
Next: Cholesky decomposition