I have an 950000x1 array of values, for example [1e15 2.5e12 ...etc]. but when I do the following to get the average value, I get values as NaN.
avg=mean(g1)
I am not able to understand why I am getting this error.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following code runs fine on my machine (Core i7, 16GB RAM, Linux Mint v12, Matlab 2012b):
This suggests to me your array of values contains an
NaNsomewhere. Note, even if your array contained numbers larger than double floating point can handle (ie on the order of 1e320 or thereabouts), then themeanfunction will returnInf, notNaN.Try
any(isnan(Vec))over your array. If it returns a1, then you’ll know it contains anNaN. If it does, then the following code will remove the NaNs.If you think this has resolved your query, then feel free to click the tick mark next to my answer. Cheers!