Main Content

addsample

Add data sample to timeseries object

Description

tsout = addsample(tsin,'Data',datavals,'Time',timevals) adds one or more data samples to a timeseries object tsin using an array of data datavals and a corresponding time vector timevals.

example

tsout = addsample(tsin,'Data',datavals,'Time',timevals,Name,Value)specifies additional information for adding data samples using one or more name-value pairs.

example

tsout = addsample(tsin,s) adds data whose information is contained in the structure s.

Examples

collapse all

Add and change data in a timeseries object.

Create a timeseries object ts1 and display the data and time samples.

ts1 = timeseries((0:10:50)',(0:5)');
ts1.Data
ans = 6×1

     0
    10
    20
    30
    40
    50

ts1.Time
ans = 6×1

     0
     1
     2
     3
     4
     5

Add a data sample to the end of ts1.

ts2 = addsample(ts1,'Data',60,'Time',6);
ts2.Data
ans = 7×1

     0
    10
    20
    30
    40
    50
    60

ts2.Time
ans = 7×1

     0
     1
     2
     3
     4
     5
     6

Change the last data sample in ts2 from 60 to 100.

ts3 = addsample(ts2,'Data',100,'Time',6,'OverwriteFlag',true);
ts3.Data
ans = 7×1

     0
    10
    20
    30
    40
    50
   100

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Sample data, specified as a numeric or logical scalar, vector, or multidimensional array.

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

Sample times, specified as a numeric scalar or vector, or a cell array of date character vectors. Valid date character vectors and strings can have the following forms:

FormatExample
dd-mmm-yyyy HH:MM:SS01-Mar-2000 15:45:17
dd-mmm-yyyy01-Mar-2000
mm/dd/yy03/01/00
mm/dd03/01
HH:MM:SS15:45:17
HH:MM:SS PM3:45:17 PM
HH:MM15:45
HH:MM PM3:45 PM
mmm.dd,yyyy HH:MM:SSMar.01,2000 15:45:17
mmm.dd,yyyyMar.01,2000
mm/dd/yyyy03/01/2000

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

Sample structure, specified as a scalar of type struct with the following optional fields:

  • s.data — Numeric array of data

  • s.time — Numeric time vector or cell array of valid date character vectors or strings

  • s.quality — Integer array of quality codes from -128 to 127

  • s.overwriteflag — Overwrite indicator specified as true to overwrite existing data samples with the added samples

Data Types: struct

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: tsout = addsample(tsin,'Data',5,'Time',3,'OverwriteFlag',true)

Quality codes, specified as [] or a scalar, vector, or multidimensional array of integers ranging from -128 to 127.

  • When the quality code value is a vector, it must have the same length as the time vector. Each element applies to the corresponding data sample.

  • When the quality code value is an array, it must have the same size as the data array. Each element applies to the corresponding element of the data array.

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

Overwrite indicator, specified as a logical value that controls whether to overwrite data samples that have the same associated time as the added samples. true indicates the added data overwrites the previous data, while false adds the sample resulting in a repeated time value.

Data Types: logical

Version History

Introduced before R2006a