Main Content


Resample timeseries time vector



tsout = resample(tsin,timevec) resamples a timeseries object tsin using a new time vector timevec. The resample function uses the interpolation method associated with tsin, which you can display using the command getinterpmethod(tsin).

tsout = resample(tsin,timevec,interpmethod) resamples tsin 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.


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


tsoutdata = tsout.Data
tsoutdata = 5×1


Input Arguments

collapse all

Input timeseries, specified as a scalar.

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