Class: timeseries

Select or interpolate timeseries data using new time vector


ts1 = resample(ts, time)
ts1 = resample(ts, time, interp_method)
ts1 = resample(ts, time, interp_method, code)


ts1 = resample(ts, time) resamples the timeseries object, ts, using the new time vector. The resample method uses the default interpolation method, which you can view by using the getinterpmethod(ts) syntax.

ts1 = resample(ts, time, interp_method) resamples the timeseries object ts using the specified interpolation method, interp_method.

ts1 = resample(ts, time, interp_method, code) resamples the timeseries object ts using the interpolation method given by the string interp_method. MATLAB® applies the code to all samples.

Input Arguments


The timeseries object that you want to resample.


The time vector you want to use to resample the timeseries object.

When ts uses date strings and time is numeric, then time is treated as specified relative to the ts.TimeInfo.StartDate property and in the same units that ts uses.


A string specifying the interpolation method. Valid interpolation methods are linear and zero-order hold, zoh .

Default: linear


An integer value that specifies the user-defined Quality code for resampling. MATLAB applies this Quality code to all samples.

Output Arguments


The timeseries object that results when you interpolate the original timeseries object with a new time vector.


This example shows how to resample a timeseries object.

Create a timeseries object.

ts1 = timeseries([1.1; 2.9; 3.7; 4.0; 3.0],1:5,'Name','speed');

View the time, data, and interpolation method.


Resample ts1 using its default interpolation method.

res_ts=resample(ts1,[1 1.5 3.5 4.5 4.9]);

View the time, data, and interpolation method for the resampled object.

Was this topic helpful?