Question

Say if I have three 1xn vectors representing n (X, Y, Z) value pairs, if I would like to generate a surface plot using these three vectors (with some smoothing), what would be the quickest way of doing it?

Was it helpful?

Solution 2

Depending on what you mean by smoothing, Curve Fitting Toolbox might be a good bet. This will allow you to do both interpolations, as well as smoothed fits to your data.

You can either use the interactive tool:

cftool

Or you can operate from the command line. In this section I've fitted a surface, used the fit object to make a prediction for z with my first x and y values, and then plotted the fitted surface. For reference, the documentation for fit can be found here: http://www.mathworks.co.uk/help/curvefit/fit.html

Example data:

load franke

Lowess Smoothing

f = fit([x,y],z, 'lowess')
zPrediction = f(x(1), y(1))
plot(f)

Piecewise Cubic Interpolant

f = fit([x,y],z, 'cubicinterp')
zPrediction = f(x(1), y(1))
plot(f)

User Defined Equation

f = fit([x,y],z, 'a*x+b*exp(y)+c')
zPrediction = f(x(1), y(1))
plot(f)

OTHER TIPS

See doc TriScatteredInterp

F = TriScatteredInterp(X, Y, Z);
%the steps of tx and ty will allow you change smoothness
tx = min(X):max(X);
ty = mix(Y):max(Y);
[qx,qy] = meshgrid(tx,ty);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top