Jeremy Minton About
Plotting Irregular Data Points in Matlab
Posted by Jeremy Minton, ,

Given three vectors x, y and z containing two locations and data values, a useful interpolation function is,

function [X,Y,Z] = vect2gridData(x,y,z,n)
%Create regular grid across data space
    [X,Y] = meshgrid(linspace(min(x),max(x),n), linspace(min(y),max(y),n))
    Z = griddata(x,y,z,X,Y)
end

And as an example of its use,

%Generate random data
x = rand(30,1);
y = rand(30,1);
z = rand(30,1);
%Plot data
surf(vect2gridData(x,y,z,60))
%mark original data points
hold on;scatter3(x,y,z,'o');hold off