Returning NaN after mean calculation?
Show older comments
I created a function that takes 5 elements of an array, calculates the mean and puts the value into another array. It does that for the next 5 elements and so on. But it's returning a NaN for like the first 15 elements.
Code:
T = readtable('MyData.xls', 'Range','E4:E23',...
'ReadVariableNames',false);
A = table2array(T)
x = zeros((numel(A)/5),1)
b = 0
while b <= (numel(x) -1)
a = b*5 + 1
x(b+1,1)= mean((A(a,1)):A((a+4),1))
b=b+1
end
It's returning :
x =
1.0e+03 *
NaN
NaN
NaN
2.7394
Does anyone know why it's NaN? My numbers aren't even big..
5146.75000000000 4683.60000000000 5011.46000000000 4831.69000000000 4836.99000000000 5107.30000000000 3356.42000000000 4973.96000000000 4253.51000000000 4885.74000000000 4949.31000000000 3308.19000000000 2960.01000000000 3181.87000000000 2738.16000000000 2393.43000000000 1904.20000000000 1703.93000000000 2834.68000000000 3085.89000000000
Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!