Matlab calcs no longer work for averages?
Ray Berkelmans
on 30 Jan 2023
Latest activity Edit by Christopher Stapels
on 31 Jan 2023
Hi
I used to have the following daily max, min and mean code working. But, this week it seems to work for max and mins but not means. Any idea what's going on?
writeAPIKey = 'xxxxxx';
% Define date range of 1 day
end1 = datetime('now')
start=datetime('today')
% Read Weight data from Field1 for last 24 hrs
[Weight, time] = thingSpeakRead(xxxxxx,'DateRange', [start,end1], 'Fields', [1]);
Wtmax = max(Weight); % Get 24hr Max
Wtmin = min(Weight); % Get 24hr Min
Wtav = mean(Weight); % Get 24hr Av
% display results
display(Wtmax, 'Wt_max'), display(Wtmin, 'Wt_min'), display(Wtav, 'Wtav');
Output:
end1 =
datetime
30-Jan-2023 14:00:35
start =
datetime
30-Jan-2023
Wt_max =
-0.0685
Wt_min =
-0.5190
Wtav =
NaN
3 Comments
Time DescendingI would suspect there are missing or nan values in the dataset. MATLAB is very explicit about how it handles these cases, but it may be different for mean than for max and min. If you find this is the case, have a look at the reference page for mean, and see the part about 'nanflag'.
Sign in to participate