Main Content

getsampleusingtime

Subset of timeseries or tscollection data

Description

tsout = getsampleusingtime(tsin,timeval) returns the single data sample of an input timeseries or tscollection corresponding to the time timeval. tsout is the same object type as tsin.

tsout = getsampleusingtime(tsin,timeval,'AllowDuplicateTimes',true) includes multiple data samples with the same time value specified in timeval.

tsout = getsampleusingtime(tsin,starttime,endtime) includes samples of tsin between the times starttime and endtime.

example

Examples

collapse all

Create a timeseries object and extract the data samples corresponding to the 2nd through 4th time values.

tsin = timeseries((1:5)',1:5);
tsout = getsampleusingtime(tsin,2,4);
tsout.Data
ans = 3×1

     2
     3
     4

Create a tscollection object from two timeseries objects and extract the data samples corresponding to the 2nd through 4th time values.

ts1 = timeseries(rand(5,1),'Name','ts1');
ts2 = timeseries(rand(5,1),'Name','ts2');
tscin = tscollection({ts1,ts2});

tscout = getsampleusingtime(tscin,2,4);
tscout.Time
ans = 3×1

     2
     3
     4

Input Arguments

collapse all

Input time series, specified as a timeseries or tscollection object.

Sample time, specified as a numeric scalar, date character vector, or datenum scalar. Valid date character vectors 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

Start time, specified as a numeric scalar, date character vector, or datenum scalar.

End time, specified as a numeric scalar, date character vector, or datenum scalar.

Tips

  • If the time vector in tsin is not relative to a calendar date, then starttime and endtime must be numeric.

  • If the time vector in tsin is relative to a calendar date, then starttime and endtime values must be date character vectors or datenum values.

Version History

Introduced before R2006a