Main Content

addsampletocollection

Add sample to tscollection

Description

example

tscout = addsampletocollection(tscin,'Time',timevals,tsname,tsdata) adds data samples to the tscollection member specified by the name tsname for one or more time values. tsdata contains the sample data.

To add samples to more than one tscollection member at a time, continue to list each tscollection member name followed by the corresponding data separated by commas. For example, the command tscout = addsampletocollection(tscin,'Time',timevals,ts1name,ts1data,ts2name,ts2data) adds samples to two timeseries in tscin simultaneously.

Examples

collapse all

Create a tscollection object from two timeseries objects and add a sample to the tscollection.

ts1 = timeseries([1.1 2.9 3.7 4.0 3.0]',1:5,'Name','Acceleration');
ts2 = timeseries([3.2 4.2 6.2 8.5 1.1]',1:5,'Name','Speed');
tscin = tscollection({ts1;ts2});
tscout = addsampletocollection(tscin,'Time',3.5,'Acceleration',10,'Speed',4.9);
tscout.Acceleration.Data
ans = 6×1

    1.1000
    2.9000
    3.7000
   10.0000
    4.0000
    3.0000

tscout.Speed.Data
ans = 6×1

    3.2000
    4.2000
    6.2000
    4.9000
    8.5000
    1.1000

Input Arguments

collapse all

Input tscollection, specified as a scalar.

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

timeseries name, specified as a character vector.

Data Types: char

timeseries 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

Tips

  • If you do not specify data samples for a tscollection member, that timeseries will contain NaN values for the times specified in timevals for numeric data. For logical data, the timeseries will contain false values.

  • When a tscollection member requires Quality values, you can specify data quality codes together with the data samples by using the following syntax:

    tsc = addsampletocollection(tsc,'Time',timevals,...
    ts1name,ts1cellarray,ts2name,ts2cellarray,...)

    Specify the data in the first cell array element and Quality in the second cell array element.

    If a tscollection member already has Quality values, but you only provide data samples, then 0 is added to the existing Quality array at the times specified in timevals.

Introduced before R2006a