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

### how to avoid NaN

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

Regards,

Ozge
```
 0

See related articles to this posting

```x = [4 5 6 NaN 10 3];
sum(x(~isnan(x)))  % Compare to sum(x)
```
 0

```"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.
>
>
> Regards,
>
> Ozge

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

help nanmean;     % <- and siblings...

us
```
 0

```"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

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

any(~isfinite(x))  % replace x with your vector.
```
 0