Be the first to rate this file! 57 Downloads (last 30 days) File Size: 2.49 KB File ID: #12395 Version: 1.3
image thumbnail

Orthogonal Linear Regression in 3D-space by using Principal Components Analysis


Ivo Petras (view profile)


26 Sep 2006 (Updated )

Orthogonal Linear Regression by using PCA

| Watch this File

File Information

Orthogonal Linear Regression in 3D-space by using Principal Components Analysis

This is a wrapper function to some pieces of the code from the Statistics Toolbox demo titled "Fitting an Orthogonal Regression Using Principal Components Analysis"
which is Copyright by the MathWorks, Inc.

Input parameters:
 - XData: input data block -- x: axis
 - YData: input data block -- y: axis
 - ZData: input data block -- z: axis
 - geometry: type of approximation ('line','plane')
 - visualization: figure ('on','off') -- default is 'on'
 - sod: show orthogonal distances ('on','off') -- default is 'on'

Return parameters:
 - Err: error of approximation - sum of orthogonal distances
 - N: normal vector for plane, direction vector for line
 - P: point on plane or line in 3D space


>> XD = [4.8 6.7 6.2 6.2 4.1 1.9 2.0]';
>> YD = [13.4 9.9 5.8 6.1 6.7 10.6 11.5]';
>> ZD = [13.7 13.1 11.3 11.8 12.5 16.2 18.5]';
>> fit_3D_data(XD,YD,ZD,'line','on','on');
>> fit_3D_data(XD,YD,ZD,'plane','on','off');

Note: Written for Matlab 7.0 (R14) with Statistics Toolbox

We sincerely thank Peter Perkins, the author of the demo, and John D'Errico for their comments.

Ivo Petras, Igor Podlubny, May 2006

An example of application can be found at:

For additional codes for the Orthogonal Linear Regression also known as Total Least Squares Method see link:


This file inspired Total Least Squares Method.

Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
28 Sep 2006

Some minor errors correction.

29 Sep 2006

Updated description, spelling correction.

04 Oct 2006

Fixing the misunderstanding around the reuse of some pieces of the code from Peter Perkins's demo.

05 Oct 2006

Updated description

18 Nov 2011 1.3

Updated description. Added screenshot.

Contact us