MATLAB: NaN when calculating average

MATLABmean2

I read data from a .xls file using xlsread. There are some 3000 rows with price data, all in number format in excel. I further try to calculate the average of previous 10 days for every day using mean2(prices(i-10,1):prices(i,1)). I do this for last 2990 rows. surprisingly a lot of these throw NaN. I have also run a check "isnan" on each element in prices and none of them tests positive. also stumbled on something:
isnumeric(NaN)
ans =
1
how is this working??

Best Answer

Although a NaN is not a number, it is of class double, and so it is numeric. If a NaN was not numeric, it could not be held in a matrix with other numbers.
Your problem is that prices(i-10,1):prices(i,1) may be empty, so mean2 returns NaN. In fact, that expression doesn't look likely to be correct. I suspect you intended to use mean2(prices(i-10:i, 1)).