Main Content

resample

Resample time vector in timeseries or tscollection

Description

example

Note

The resample function applies to objects created using timeseries or tscollection. For information on resampling a timetable, which is recommended over timeseries and tscollection, see retime.

tsout = resample(tsin,timevec) resamples a time series or collection using a new time vector. The resample function uses the interpolation method associated with each time series.

example

tsout = resample(tsin,timevec,interpmethod) resamples using a specified interpolation method. interpmethod can be 'linear' for linear interpolation or 'zoh' for zero-order hold.

tsout = resample(tsin,timevec,interpmethod,code) applies the quality codes in code to all samples.

Examples

collapse all

Create a timeseries object, and resample it using linear interpolation according to the times in timevec. Compare the original data to the resampled data.

tsin = timeseries([1.1 2.9 3.7 4.0 3.0]',1:5);
tsout = resample(tsin,[1 1.5 3.5 4.5 4.9]);
tsindata = tsin.Data
tsindata = 5×1

    1.1000
    2.9000
    3.7000
    4.0000
    3.0000

tsoutdata = tsout.Data
tsoutdata = 5×1

    1.1000
    2.0000
    3.8500
    3.5000
    3.1000

Resample a tscollection object made up of two timeseries objects.

Create a tscollection object from two timeseries objects.

ts1=timeseries([1.1 2.9 3.7 4.0 3.0]',1:5,'Name','Acceleration');
ts2=timeseries([3.2 4.2 6.2 8.5 1.1]',1:5,'Name','Speed');
tscin = tscollection({ts1,ts2})
Time Series Collection Object: unnamed

Time vector characteristics

      Start time            1 seconds
      End time              5 seconds

Member Time Series Objects:

      Acceleration
      Speed

Resample the data in tscin according to a new time vector using zero-order hold interpolation.

tsout = resample(tscin,[1 1.5 3.5 4.5 4.9],'zoh')
Time Series Collection Object: unnamed

Time vector characteristics

      Start time            1 seconds
      End time              4.900000e+00 seconds

Member Time Series Objects:

      Acceleration
      Speed

Input Arguments

collapse all

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

New time vector, specified as a vector of times for resampling.

When the original time vector contains dates and times but timevec is numeric, resample defines timevec relative to the tsin.TimeInfo.StartDate property using the existing units.

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

Interpolation method, specified as one of the following options:

  • 'linear' — Linear interpolation

  • 'zoh' — Zero-order hold

Quality codes, specified as [] or a scalar, vector, or multidimensional array of integers ranging from -128 to 127.

  • When the quality code value is a vector, it must have the same length as the time vector. Each element applies to the corresponding data sample.

  • When the quality code value is an array, it must have the same size as the data array. Each element applies to the corresponding data element of the data array.

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

Version History

Introduced before R2006a