timeseries.mean
timeseries: v = mean (ts)
timeseries: v = mean (ts, name, value, …)
Return the mean of a series over time.
v = mean (ts) returns the mean of each data element
over time, so v has the size of one sample; with 'time'
weighting it is the time-weighted mean. v is double
whatever the class of the data, and [] for a series with no
samples.
v = mean (ts, name, value, …) takes
these options, which all nine statistics share, the names matched in any
case:
'Quality'NaN, a sum 0. A code no sample has leaves
nothing out, with a warning.'MissingData''remove', the default, leaves missing values out;
'interpolate' fills those between samples linearly in time
first.'Weighting''none', the default, or 'time', which weights each sample
by the time it covers: an interior sample by the mean of its two
intervals, an end sample by its one interval, the weights scaled to a
mean of 1, so that uniform time changes nothing. NaN is missing while TreatNaNasMissing is true;
when it is false, mean, median, std,
var and sum give NaN where the data holds one,
while min, max, mode and iqr still skip it,
as in MATLAB.
MATLAB applies 'time' weighting by multiplying the data by the
weights and taking the ordinary statistic of the product, which is
right for mean and sum only: there the minimum of
[1 2 4 8 16] at times [0 1 3 7 8] is 0.5556. Here each
statistic is the time-weighted one: 1 for that minimum. MATLAB also
fails on logical data, and in std, var and iqr on
integer data, which here are computed in double.
See also: timeseries.median, timeseries.std, timeseries.sum
Source Code: timeseries
The statistics run over time. NaN is left out while TreatNaNasMissing is true, and 'Quality' names codes whose samples are left out.
ts = timeseries ([2; NaN; 4; 100], [0; 1; 2; 3], [0; 0; 0; 5]); mean (ts)
ans = 35.333
mean (ts, 'Quality', 5)
ans = 3
'Weighting', 'time' weights each sample by the time it stands for, which matters on irregular times. The other statistics take the same options.
ts = timeseries ([1; 2; 4; 8; 16], [0; 1; 3; 7; 8]); mean (ts)
ans = 6.2000
mean (ts, 'Weighting', 'time')
ans = 5.7778
median (ts, 'Weighting', 'time')
ans = 4.7273