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

    %% Interpolation of Multiple 1-D Value Sets  
% This example shows how to interpolate three 1-D data sets in a single
% pass using |griddedInterpolant|. This is a faster alternative to looping
% over your data sets.

%% 
% Define the _x_-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]  

%% 
% Create a 2-D grid of sample points. 
samplePoints = {x, 1:size(V,2)}; 

%%
% This compact notation specifies a full 2-D grid. The first element,
% |samplePoints{1}|, contains the _x_-coordinates for |V|, and
% |samplePoints{2}| contains the _y_-coordinates. The orientation of each
% coordinate vector does not matter.

%% 
% Create the interpolant, |F|, by passing the sample points and sample
% values to |griddedInterpolant|.
F = griddedInterpolant(samplePoints,V);  

%% 
% Create a 2-D query grid with |0.5| spacing along |x| over all columns of
% |V|.
queryPoints = {(1:0.5:5),1:size(V,2)};  

%% 
% Evaluate the interpolant at the _x_-coordinates for each value set. 
Vq = F(queryPoints)