1

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?

2 Answers 2

2

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');
Sign up to request clarification or add additional context in comments.

Comments

1

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)

1 Comment

Great idea and now I know what the non-parametric fitting is used for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.