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

    %% Evaluate Outside the Domain of X and Y  

% Copyright 2015 The MathWorks, Inc.


%% 
% Coarsely sample a function over the range, |[-2, 2]| in both dimensions. 
[X,Y] = meshgrid(-2:0.75:2);
R = sqrt(X.^2 + Y.^2)+ eps;
V = sin(R)./(R);  

%% 
% Plot the coarse sampling. 
figure
surf(X,Y,V)
xlim([-4 4])
ylim([-4 4])
title('Original Sampling')     

%% 
% Create the query grid that extends beyond the domain of |X| and |Y|. 
[Xq,Yq] = meshgrid(-3:0.2:3);  

%% 
% Perform cubic interpolation within the domain of |X| and |Y|, and assign all
% queries that fall outside to zero. 
Vq = interp2(X,Y,V,Xq,Yq,'cubic',0);  

%% 
% Plot the result. 
figure
surf(Xq,Yq,Vq)
title('Cubic Interpolation with Vq=0 Outside Domain of X and Y');