Main Content

gettsbetweenevents

Create timeseries between events

Description

example

tsout = gettsbetweenevents(tsin,tsevent1,tsevent2) returns a timeseries object with samples occurring between the events tsevent1 and tsevent2 in the input timeseries tsin. The arguments tsevent1 and tsevent2 can be either tsdata.event objects or character vectors containing the names of the events. When tsevent1 and tsevent2 are tsdata.event objects, the times defined by the events specify the time. When tsevent1 and tsevent2 are character vectors, the first tsdata.event object in the Events property of tsin that matches the event names specifies the time.

tsout = gettsbeforeevent(tsin,tsevent1,tsevent2,n1,n2) returns a timeseries object with samples between two events in tsin, where n1 is the number of the event occurrence for tsevent1 and n2 is the number of the event occurrence for tsevent2.

Examples

collapse all

Create a timeseries object with events occurring at time samples 1 and 3.

tsin = timeseries((1:5)');
tsevent1 = tsdata.event('StartEvent',1);
tsevent2 = tsdata.event('EndEvent',3);
tsin = addevent(tsin,[tsevent1 tsevent2]);

Create a new timeseries object that contains the data between the two event samples.

tsout = gettsbetweenevents(tsin,'StartEvent','EndEvent');
tsout.Time
ans = 3×1

     1
     2
     3

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Data Types: timeseries

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

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

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

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

End event number, specified as a scalar integer corresponding to the n2 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 tsevent1 and tsevent2 use numeric time, the time selected is treated as a date that is calculated relative to the StartDate property in tsin.TimeInfo.

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

Version History

Introduced before R2006a