Main Content

gettsbeforeevent

Create timeseries before event

Description

tsout = gettsbeforeevent(tsin,tsevent) returns a timeseries object with samples occurring before the event tsevent in the input timeseries tsin. The argument tsevent can be either a tsdata.event object or a character vector containing the name of the event. When tsevent is a tsdata.event object, the time defined by tsevent specifies the time. When tsevent is a character vector, the first tsdata.event object in the Events property of tsin that matches the event name specifies the time.

example

tsout = gettsbeforeevent(tsin,tsevent,n) returns a timeseries object with samples before an event in tsin, where n is the number of the event occurrence for the event tsevent.

Examples

collapse all

Create a timeseries object with an event occurring at time sample 2.

tsin = timeseries((1:5)');
tsevent = tsdata.event('MyEvent',2);
tsin = addevent(tsin,tsevent);
tsin.Events
    EventData: []
         Name: 'MyEvent'
         Time: 2
        Units: 'seconds'
    StartDate: ''

Create a new timeseries object that contains the data before the event sample.

tsout = gettsbeforeevent(tsin,'MyEvent');
tsout.Time
ans = 2×1

     0
     1

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Data Types: timeseries

Event, specified as a scalar tsdata.event object or a character vector containing the name of an event.

Event number, specified as a scalar integer corresponding to the nth tsdata.event of a timeseries object.

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

Tips

  • When the input timeseries object tsin contains date character vectors and tsevent uses numeric time, the time selected by tsevent is treated as a date that is calculated relative to the StartDate property in tsin.TimeInfo.

  • When tsin uses numeric time and tsevent uses calendar dates, the time selected by tsevent is treated as a numeric value that is not associated with a calendar date.

Version History

Introduced before R2006a