MATLAB Answers

Surface fit of 3D plot

20 views (last 30 days)
Davide Bassignana
Davide Bassignana on 3 Dec 2017
Answered: Elizabeth Reese on 5 Dec 2017
I have the plot presented in figure, every line was plotted using a constant x coordinate, a vector y which is the same for every line and a vector z which depend on the x-coordinate (pdf attached). I would like to add a fitting surface, but since every line was created with a plot command I don't know how could I possibly do it.
hold on
grid on
rotate3d on

Answers (1)

Elizabeth Reese
Elizabeth Reese on 5 Dec 2017
Let's assume that your x_coord is n x 7 and that y_beam is n x 1. Then each of x.N2.pi for i = 0:6 is n x 1.
In order to use fit, the surface fitting function, these need to be the same size and all vectors. You can build these vectors with the following:
X = x_coord(:) % this returns the elements of x_coord in column order
Y = repmat(y_beam, 7,1) % this creates a column vector of 7 y_beams stacked on top of one another
Z = [z.N2.p0 ; z.N2.p1 ; z.N2.p2 ; z.N2.p3 ; z.N2.p4 ; z.N2.p5 ; z.N2.p6] % This stacks the z.N2.pi vectors on top of one another
Then you can do the fitting:
f = fit([X,Y],Z,'fittype'); % change this to be the fit type that best matches your problem
plot(f, [X,Y], Z);
Here is the documentation for the fit function.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!