% example of 2-D interpolation % calculate randomly distributed x-y locations x = rand(100,1)*16 -8; y = rand(100,1)*16 -8; % calculate function at x-y locations r = sqrt(x.^2 + y.^2) + eps; z = sin(r)./r; % calculate evenly spaced x and y vectors xlin = linspace(min(x),max(x),33); ylin = linspace(min(y),max(y),33); % calculate grid [X,Y] = meshgrid(xlin,ylin); % interpolate data onto grid points Z = griddata(x,y,z,X,Y,'cubic'); mesh(X,Y,Z) % interpolated surface axis tight; hold on % display random values (data usded for interpolation) plot3(x,y,z,'.r','MarkerSize',15) hold off