odehybrid
by An Uncommon Lab

interpd

An interpolation function for time series which may have multiple values at a single timestep (e.g., discrete updates). It works like MATLAB's built-in interp1.

xi = interpd(t, x, ti);
xi = interpd(t, x, ti, mode);
xi = interpd(t, x, ti, mode, ...);

Inputs

tTimes (n-by-1)
xStates (n-by-m)
tiOutput times (p-by-1)
mode'-' for left-most values, '+' for right-most values (default).
...Any additional arguments to be based along to interp1 (e.g., 'nearest').

Outputs

xiStates corresponding to output times (p-by-m)

Examples

Create some times and states. Note that there are two states at t=3.

t = [2.76, 2.91, 3,   3,   3.12].';
x = [0.2,  0.3,  0.4, 1.1, 1.2].';

Create the desired output times.

ti = (2.8:0.1:3.1).';

Interpolate (t, x) linearly at ti, keeping the right-most values.

xi = interpd(t, x, ti).'
xi =
    0.2267    0.2933    1.1000    1.1833

Interpolate (t, x) linearly at ti, keeping the left-most values.

xi = interpd(t, x, ti, '-').'
xi =
    0.2267    0.2933    0.4000    1.1833

Interpolate (t, x) using 'nearest' at ti, keeping the left-most values.

xi = interpd(t, x, ti, '-', 'nearest').'
xi =
    0.2000    0.3000    0.4000    1.2000

See Also

Examples