addts

Add timeseries object to tscollection object

Syntax

tsc = addts(tsc,ts)
tsc = addts(tsc,ts)
tsc = addts(tsc,ts,Name)
tsc = addts(tsc,Data,Name)

Description

tsc = addts(tsc,ts) adds the timeseries object ts to tscollection object tsc.

tsc = addts(tsc,ts) adds a cell array of timeseries objects ts to the tscollection tsc.

tsc = addts(tsc,ts,Name) adds a cell array of timeseries objects ts to tscollection tsc. Name is a cell array of strings that gives the names of the timeseries objects in ts.

tsc = addts(tsc,Data,Name) creates a new timeseries object from Data with the name Name and adds it to the tscollection object tsc. Data is a numerical array and Name is a string.

Examples

The following example shows how to add a time series to a time-series collection:

  1. Create two timeseries objects, ts1 and ts2.

    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');
    
  2. Create a time-series collection tsc, which includes ts1.

    tsc = tscollection(ts1);
  3. Add ts2 to the tsc collection.

    tsc = addts(tsc, ts2);
  4. To view the members of tsc, type

    tsc

    at the MATLAB® prompt. the response is

    Time Series Collection Object: unnamed
    
    Time vector characteristics
    
          Start time            1 seconds
          End time              5 seconds
    
    Member Time Series Objects:
    
          acceleration
          speed

The members of tsc are listed by name at the bottom: acceleration and speed. These are the Name properties of the timeseries objects ts1 and ts2, respectively.

More About

expand all

Tips

The timeseries objects you add to the collection must have the same time vector as the collection. That is, the time vectors must have the same time values and units.

Suppose that the time vector of a timeseries object is associated with calendar dates. When you add this timeseries to a collection with a time vector without calendar dates, the time vectors are compared based on the units and the values relative to the StartDate property. For more information about properties, see the timeseries reference page.

Was this topic helpful?