File Exchange

## plane_fit

version 1.0 (1.48 KB) by

Fits a plane to 3D data using singular value decomposition

Updated

Fits a plane of the from z=Ax+By+C to the data and provides the coefficients A,B and C. The functions uses the svd command (singular value decomposition).

%% EXAMPLE
[x,y]=meshgrid(linspace(0,10,20),linspace(0,10,20));
a=1; b=2; c=-2;
z=(a*x)+(b*y)+c;
x=x(:); y=y(:); z=z(:);
z=z+(randn(length(z),1));
[A,B,C]=plane_fit(x,y,z);
[X,Y]=meshgrid(linspace(min(x),max(x),20),linspace(min(y),max(y),20));
Z=(A*X)+(B*Y)+C;
plot3(x,y,z,'r.'); hold on; grid on;
surf(X,Y,Z,'FaceColor','g'); alpha(0.5);
title(['a=',num2str(a), ', A=',num2str(A),', b=',num2str(b),', B=',num2str(B),', c=',num2str(c),', C=',num2str(C)]);

Arman Rezaee

x I'm tc

### x I'm tc (view profile)

Doesn't seem to work, but perhaps it is not doing what I hope it is doing.

Meghana Dinesh

### Meghana Dinesh (view profile)

Hi, I want to use your code for my project.

But I have a problem with it.........I am not familiar with this topic though. I'm not sure I am using my outputs from this function in the right way to plot my plane.

Although your function fits properly with my data points, the angle detected between two planes does not seem right.

Thank you.

Nathan Tomlin

Jan Neggers

### Jan Neggers (view profile)

It worked perfectly for me. Although i didn't understand SVD and therefore tried it with a least squares method, which also works.

Gavrilo Bozovic

### Gavrilo Bozovic (view profile)

Didn't work for me, and the data was as planar as one could expect it to be...

Gavrilo Bozovic

### Gavrilo Bozovic (view profile)

##### MATLAB Release
MATLAB 7.4 (R2007a)