getsamples

Subset of a timeseries chosen by sample index.

Category: Language Fundamentals > Data Types

Syntax

tsout = getsamples(ts, idx)

Returns a new timeseries with the samples at the indices idx.

Description

Unlike getdatasamples, which returns only numbers, getsamples keeps the time stamps with the data, so the result is still a time series. Indices refer to sample order, not to time values; use getsampleusingtime to select by time.

Input arguments

ts
timeseries object.
idx
Vector of sample indices.

Output arguments

tsout
timeseries holding the selected times and data.

Example

Samples 2 and 3

ts = timeseries((10:10:50)', (0:4)');
s = getsamples(ts, 2:3);
disp(s.Time')
disp(s.Data')
Output
     1     2
    20    30

See also

getdatasamples getsampleusingtime timeseries resample addsample