3.33333

3.3 | 4 ratings Rate this file 22 Downloads (last 30 days) File Size: 1.48 KB File ID: #22042
image thumbnail

plane_fit

by

 

Fits a plane to 3D data using singular value decomposition

| Watch this File

File Information
Description

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)]);

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
22 Aug 2012 Nathan Tomlin  
27 Nov 2008 Jan Neggers

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

17 Nov 2008 Gavrilo Bozovic

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

17 Nov 2008 Gavrilo Bozovic  

Contact us