Main Content

setinterpmethod

Set default interpolation method for timeseries object

Description

example

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.

Examples

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');
plot(ts)

Figure contains an axes. The axes with title Time Series Plot:unnamed contains an object of type stair.

Set the default interpolation method using a function handle.

fun = @(newtime,oldtime,olddata)...
               interp1(oldtime,olddata,newtime,...
                       'linear','extrap');
ts = setinterpmethod(ts,fun);
plot(ts)

Figure contains an axes. The axes with title Time Series Plot:unnamed contains an object of type line.

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

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

Figure contains an axes. The axes with title Time Series Plot:unnamed contains an object of type line.

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