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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Class: timeseries

Variance of timeseries data


ts_var = var(ts)
ts_var = var(ts,Name,Value)


ts_var = var(ts) returns the variance of

ts_var = var(ts,Name,Value)uses additional options specified by one or more Name,Value pair arguments.

Input Arguments


The timeseries object for which you want the variance of the data.

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.


A string specifying one of two possible values, remove or interpolate, indicating how to treat missing data during the calculation.

Default: remove


A vector of integers, indicating which quality codes represent missing samples (for vector data) or missing observations (for data arrays with two or more dimensions).


A string specifying one of two possible values, none or time.
When you specify time, larger time values correspond to larger weights.

Output Arguments


The variance of, as follows:

  • When ts.Data is a vector, then ts_var is the variance of ts.Data values.

  • When ts.Data is a matrix, and IsTimeFirst is true, and the first dimension of ts is aligned with time, then ts_var is a row vector containing the variance of each column of ts.Data.

When ts.Data is an N-dimensional array, var always operates along the first nonsingleton dimension of ts.Data.


The following example calculates the variance values of a multivariate timeseries object. MATLAB® calculates the variance independently for each data column in the timeseries object.

Load a 24-by-3 data array. Then create a timeseries object with 24 time values.

load count.dat
count_ts = timeseries(count,[1:24],'Name','CountPerSecond');

Calculate the variance of each data column.


MATLAB returns:

1.0e+03 *
  0.6437    1.7144    4.6278


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?