MATLAB: Plotting griddata

plot griddata

Hey All, I was wondering if there was a way to modify the griddata program to include plotting. Given that I am using data points I know I will have to use meshgrid and was trying to figure out how it would be possible to include into the program. Any ideas? Mel

Best Answer

From the doc:
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
ti = -2:.25:2;
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI);
mesh(XI,YI,ZI), hold
plot3(x,y,z,'o'), hold off
%
%
%
%
EDIT
So do this:
>> edit griddata % Once the file is up, do this:
ctrl+a,ctrl+c,ctrl+n,ctrl+v,ctrl+s % I recommend using mygriddata
Then look in the new file, and find the last switch statement of the main function. Immediately after that switch statement, put this:
mesh(xi,yi,zi)
hold on
plot3(x,y,z,'o')
hold off
Or whatever you want.