www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/GriddedInterpolantInOneDimensionExample.m

    %% griddedInterpolant in One Dimension
% This example shows how to create and plot a 1-D interpolant using
% |griddedInterpolant| with a cubic interpolation method.

%%
% Create a coarse grid and sample values.
X = [1 2 3 4 5];
V = [12 6 15 9 6];

%%
% Construct the |griddedInterpolant| using a cubic interpolation method.
F = griddedInterpolant(X,V,'cubic')

%%
% The |GridVectors| property contains the compact grid specifying the
% coordinates of the sample values |V|. The |Method| property specifies the
% interpolation method. Notice that we specified |'cubic'| when we created
% |F|. If you omit the |Method| argument, the default interpolation method,
% |linear|, will be assigned to |F|.

%%
% You can access any of the properties of |F| in the same way you would
% access the fields in a |struct|.
F.GridVectors;          % Displays the grid vectors as a cell array
F.Values;               % Displays the sample values
F.Method;               % Displays the interpolation method

%%
% Interpolate over finer intervals with 0.1 spacing.
Xq = (1:0.1:5);
Vq = F(Xq);

%%
% Plot the result.
plot(X,V,'o');
hold on
plot(Xq,Vq,'-');
legend('samples','Cubic Interpolation');