This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Class: timeseries

Add data sample to timeseries object


ts1 = addsample(ts, s)
ts1 = addsample(ts, 'Data', data-value, 'Time',time-value,..., Name,Value)


ts1 = addsample(ts, s) adds one or more new data samples stored in a structure s to the timeseries object ts.

ts1 = addsample(ts, 'Data', data-value, 'Time',time-value,..., Name,Value) adds one or more data samples to the timeseries object ts along with additional options specified by one or more Name,Value pair arguments.


  • If N is the number of data samples, you can get the sample size of each time with SampleSize = getsamplesize(ts).

    When ts.IsTimeFirst is true, the size of the data is N-by-SampleSize. When ts.IsTimeFirst is false, the size of the data is SampleSize-by-N.

Input Arguments


A structure that you must define before passing as an argument to addsample. It consists of the following optional fields:


  • s.time

  • s.quality

  • s.overwriteflag


A numeric data value.


A valid time vector.

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.


Array of data quality codes.

Default: []


Logical value that controls whether to overwrite a data sample at the same time with the new sample you are adding to your timeseries object. When set to true, the new sample overwrites the old sample at the same time.

Default: false

Output Arguments


The timeseries object that results when you add the specified samples to the original timeseries object.


data sample

One or more values recorded at a specific time. The number of data samples in a time series is the same as the length of the time vector.


Add a data value of 420 at time 3:

ts = ts.addsample('Time',3,'Data',420);

Add a data value of 420 at time 3 and specify quality code 1 for this data value. Set the OverwriteFlag to overwrite an existing value at time 3.

ts = ts.addsample('Data',3.2,'Quality',1,'OverwriteFlag',... 

Introduced before R2006a

Was this topic helpful?