Documentation

sum

Class:timeseries

Sum oftimeseriesdata

Syntax

ts_sm = sum(ts)
ts_sm = sum(ts,Name,Value)

Description

ts_sm= sum(ts)returns the sum of thetimeseriesdata.

ts_sm= sum(ts,Name,Value)specifies additional options with one or moreName,Valuepair arguments.

Input Arguments

ts

Thetimeseriesobject for which you want the sum of the data.

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside single quotes (' '). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.

'MissingData'

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

Default:remove

'Quality'

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).

'Weighting'

A string specifying one of two possible values,noneortime.
When you specifytime更大的时间值对应to larger weights.

Output Arguments

ts_sm

The sum of thetimeseriesdata, as follows:

  • Whents.Datais a vector, ts_sm is the sum ofts.Datavalues.

  • Whents.Datais a matrix, andIsTimeFirstistrue, and the first dimension oftsis aligned with time, then ts_sm is a row vector containing the sum of each column ofts.Data.

Whents.Datais a N-dimensional array,sumalways operates along the first nonsingleton dimension ofts.Data.

Examples

Calculate the sum of each data column for atimeseriesobject:

% Load a 24-by-3 data array: load count.dat % Create a timeseries object with 24 time values: count_ts = timeseries(count,1:24,'Name','CountPerSecond'); % Calculate the sum of each data column for this timeseries object: sum(count_ts)

MATLAB®returns:

768 1117 1574

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 thetimeseriesobject 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.

Introduced before R2006a

Was this topic helpful?