timeseries

Methods

Method Reference: timeseries.getsampleusingtime

timeseries: ts2 = getsampleusingtime (ts, t)

timeseries: ts2 = getsampleusingtime (ts, t, 'AllowDuplicateTimes', tf)

timeseries: ts2 = getsampleusingtime (ts, t1, t2)

Return a series of the samples at a time or between two times.

ts2 = getsampleusingtime (ts, t) returns the series ts holding only the sample at time t. When several samples share that time the call is refused, unless 'AllowDuplicateTimes' is true, which returns them all. MATLAB returns them all for false too.

ts2 = getsampleusingtime (ts, t1, t2) returns the samples from t1 to t2, both included.

For a series with no TimeInfo.StartDate the times are numbers in its units. For a series with one they are dates: text, a datenum, or a datetime, which MATLAB does not accept. No sample in range, NaN, or t1 after t2 give a series with no samples. Every property but the samples is kept; MATLAB names the result 'unnamed' and, when it is empty, resets every property.

See also: timeseries.getsamples, timeseries.delsample

Source Code: timeseries

One time gives the sample at that time; two give every sample between them, both ends included.

 ts = timeseries ([10; 20; 30; 40; 50], [0; 1; 2; 3; 4]);
 s = getsampleusingtime (ts, 2);
 [s.Time, s.Data]
ans =

    2   30
 s = getsampleusingtime (ts, 0.5, 3);
 [s.Time, s.Data]
ans =

    1   20
    2   30
    3   40

A dated series takes dates.

 ts = timeseries ([3; 5; 4; 6], {'01-Mar-2024', '02-Mar-2024', ...
                                 '03-Mar-2024', '04-Mar-2024'});
 s = getsampleusingtime (ts, '02-Mar-2024', '03-Mar-2024');
 getabstime (s)
ans =
  2x1 cell array

    {'02-Mar-2024 00:00:00'}    
    {'03-Mar-2024 00:00:00'}