0

I am wondering if anyone knows (or is it possible?) how to generate a trend equation from a 3D surf plot from Matlab? I understand that we can create trendline for 2D plots (linear and nonlinear) and show its equation, but how about 3D plot? Can we create something like:

z = ax + by?

Regards Kit

kit
  • 73
  • 1
  • 2
  • 5

1 Answers1

0

If you have the curve fitting toolbox you can fit 3D surfaces using cftool as described here.

Here's an example:

[X,Y] = meshgrid(1:100,1:100);
X = reshape(X,numel(X),1);
Y = reshape(Y,numel(Y),1);
Z = 3*X+4*Y;
plot3(X,Y,Z)

f = fit([X, Y], Z, 'poly11');
coeffvalues(f)
Molly
  • 13,240
  • 4
  • 44
  • 45
  • hi, I have plotted the surface plot using some data (without equation). Now I am actually looking forward to use Matlab to generate the equation for me from the plot itself. The Basic Fitting is grayed out (disabled) from the Tools. – kit Apr 03 '13 at 01:24
  • Basic fitting won't work for surfaces. You can type ver at the command prompt to find out if you have the curve fitting box. If not, this answer might help: http://stackoverflow.com/questions/4497448/curve-fitting-without-toolbox – Molly Apr 03 '13 at 01:40
  • I have curve fitting toolbox in my Matlab. But is it possible to use it and generate the equation I want in the form of z = ax + by? – kit Apr 03 '13 at 01:51
  • Yes. I've added an example. There's more information in the link I included. – Molly Apr 03 '13 at 02:18
  • I used Surface Fitting Tool (sftool) instead for 3D equation generation. This is the results I got from your example: – kit Apr 03 '13 at 02:25
  • Linear model Poly43: f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2 + p03*y^3 + p40*x^4 + p31*x^3*y + p22*x^2*y^2 + p13*x*y^3 – kit Apr 03 '13 at 02:35
  • `Coefficients (with 95% confidence bounds): p00 = -1.837e-012 (-2.372e-012, -1.302e-012) p10 = 3 (3, 3) p01 = 4 (4, 4) p20 = -1.283e-014 (-1.419e-014, -1.148e-014) p11 = -1.275e-015 (-2.334e-015, -2.173e-016) p02 = -4.633e-016 (-1.162e-015, 2.357e-016) p30 = 1.306e-016 (1.123e-016, 1.49e-016) p21 = 1.855e-017 (4.498e-018, 3.261e-017) p12 = 4.552e-018 (-9.503e-018, 1.861e-017) p03 = 1.857e-018 (-2.614e-018, 6.328e-018) p40 = -3.571e-019 (-4.452e-019, -2.689e-019) ` – kit Apr 03 '13 at 02:36
  • ` p31 = -1.011e-019 (-1.78e-019, -2.427e-020) p22 = -4.543e-020 (-1.209e-019, 3.004e-020) p13 = 1.747e-020 (-5.941e-020, 9.434e-020)` – kit Apr 03 '13 at 02:37
  • `Goodness of fit: SSE: 4.564e-020 R-square: 1 Adjusted R-square: 1 RMSE: 2.138e-012` – kit Apr 03 '13 at 02:37