Main Content

var

Variance of timeseries data

Description

tsvar = var(ts) returns the variance of the data samples in a timeseries object.

example

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

Examples

collapse all

Create a timeseries object and compute the variance of the sample data.

ts = timeseries((1:10)');
tsvar = var(ts)
tsvar = 
9.1667

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Data Types: timeseries

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: tsvar = var(ts,'Quality',-99,'MissingData','remove')

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.

Algorithms

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.

    Note

    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.

Version History

Introduced before R2006a

See Also

| | |