Interpolation of Multiple 1-D Value Sets
This example shows how to interpolate three 1-D data sets in a single pass usinggriddedInterpolant
. This is a faster alternative to looping over your data sets.
Define thex-coordinates that are common to all value sets.
x = (1:5)';
Define the sets of sample points along the columns of matrix V.
V = [x, 2*x, 3*x]
V =5×31 2 3 2 4 6 3 6 9 4 8 12 5 10 15
Create the interpolantF
by passing the sample points and sample values togriddedInterpolant
. With this setup,griddedInterpolant
interpretsV
as containing three different 1-D data sets defined at the samex-values.
F = griddedInterpolant(x,V);
Create a vector of query points with0.5
spacing.
qx = 1:0.5:5;
Evaluate the interpolant at thex-coordinates for each value set.
Vq = F(qx)
Vq =9×31.0000 2.0000 3.0000 1.5000 3.0000 - 4.5000 2.0000 4.0000 6.0000 2.5000 5.0000 7.5000 3.0000 6.0000 9.0000 3.5000 7.0000 10.5000 4.0000 8.0000 12.0000 4.5000 9.0000 13.5000 5.0000 10.0000 15.0000