MATLAB: Smoothen 3d surf plot

interp2smoothensurf

I have a recurring question about smoothening a surf plot.
I have a vector x of dimension Nx and a vector y of dimension Ny, with Nx different from Ny.
I have a matrix z of dimension Nx * Ny. I plot the data with 'surf(y,x,z)' which works fine. Now I'd like to smoothen the plot. I read that this can be done with interp2, but i did not manage to do so.
I'd be very glad for some ideas on how to do this.

Best Answer

num_segments = 100; %divide the range into this many pieces
minx = min(x);
maxx = max(x);
miny = min(y);
maxy = max(y);
smoothx = linspace(minx, maxx, num_segments+1);
smoothy = linspace(miny, maxy, num_segments+1);
smoothz = interp2( x, y, z.', smoothx.', smoothy );
surf(smoothy, smoothx, smoothz);