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:
how to avoid NaN

Subject: how to avoid NaN

From: Ozge Taskan

Date: 29 Apr, 2010 05:50:21

Message: 1 of 5

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

Subject: how to avoid NaN

From: Matt Fig

Date: 29 Apr, 2010 06:05:23

Message: 2 of 5

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

Subject: how to avoid NaN

From: us

Date: 29 Apr, 2010 06:29:31

Message: 3 of 5

"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

Subject: how to avoid NaN

From: Ozge Taskan

Date: 29 Apr, 2010 06:32:09

Message: 4 of 5

"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

Subject: how to avoid NaN

From: Matt Fig

Date: 29 Apr, 2010 07:00:23

Message: 5 of 5

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

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

Tags for 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