This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Mean of timeseries data


tsmean = mean(ts)
tsmean = mean(ts,Name,Value)



tsmean = mean(ts) returns the mean of the data samples in a timeseries object.

tsmean = mean(ts,Name,Value) specifies additional options when computing the mean using one or more name-value pair arguments. For example, tsmean = mean(ts,'Quality',-99,'MissingData','remove') defines -99 as the missing sample quality code, and removes the missing samples before computing the mean.


collapse all

Create a timeseries object and compute the mean of the data samples.

ts = timeseries((1:5)');
tsmean = mean(ts)
tsmean = 3

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Data Types: timeseries

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: tsmean = mean(ts,'Quality',-99,'MissingData','remove')

collapse all

Missing value indicator, specified a scalar, vector, matrix, or multidimensional array of integers ranging from -128 to 127. Each element is a quality code to treat as missing data.

By default, missing data is removed before computing. To interpolate the data instead of removing it, specify the name-value pair 'MissingData','interpolation'.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Missing data method, specified as either 'remove' to remove missing values or 'interpolate' to fill missing values by interpolating the data. Specify the 'Quality' name-value pair to indicate which data samples are considered missing.

Weights, specified as 'none' or 'time'.
When you specify 'time', larger time values correspond to larger weights.


MATLAB® determines weighting by:

  1. Attaching a weighting to each time value, depending on its order, as follows:

    • First time point — The duration of the first time interval (t(2) - t(1)).

    • Time point that is neither the first nor last time point — The duration between the midpoint of the previous time interval to the midpoint of the subsequent time interval ((t(k + 1) - t(k))/2 + (t(k) - t(k - 1))/2).

    • Last time point — The duration of the last time interval (t(end) - t(end - 1)).

  2. Normalizing the weighting for each time by dividing each weighting by the mean of all weightings.


    If the timeseries object is uniformly sampled, then the normalized weighting for each time is 1.0. Therefore, time weighting has no effect.

  3. Multiplying the data for each time by its normalized weighting.

See Also

| | | |

Introduced before R2006a

Was this topic helpful?