This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Set default interpolation method for timeseries object


ts = setinterpmethod(ts,interpmethod)
ts = setinterpmethod(ts,fun)
ts = setinterpmethod(ts,interpobj)



ts = setinterpmethod(ts,interpmethod) sets the default interpolation method of a timeseries object. interpmethod can be 'linear' for linear interpolation or 'zoh' for zero-order hold.

ts = setinterpmethod(ts,fun) uses a function handle fun to set the default interpolation method of ts.

ts = setinterpmethod(ts,interpobj) uses a tsdata.interpolation object interpobj to replace the interpolation object stored in ts.


collapse all

Set the interpolation method of a timeseries object in three ways.

Create a timeseries object and set the interpolation method to zero-order hold.

ts = timeseries(rand(100,1),1:100);
ts = setinterpmethod(ts,'zoh');

Set the default interpolation method using a function handle.

fun = @(newtime,oldtime,olddata)...
ts = setinterpmethod(ts,fun);

Set the default interpolation method to a tsdata.interpolation object.

interpobj = tsdata.interpolation(fun);
ts = setinterpmethod(ts,interpobj);

Input Arguments

collapse all

Input timeseries, specified as a scalar.

Data Types: timeseries

Interpolation method, specified as one of the following options:

  • 'linear' — Linear interpolation

  • 'zoh' — Zero-order hold

Interpolation method handle, specified as a scalar function handle defining the interpolation method. The order of input arguments for the function handle must be newtime, oldtime, and olddata. A single output argument must contain the interpolated data.

Data Types: function_handle

Interpolation object, specified as a tsdata.interpolation object that directly replaces the interpolation object stored in ts.

Introduced before R2006a