www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgmathsobject/private/isColinear.m

    function linearflag = isColinear(X)
%ISCOLINEAR Test for colinearity
%
%   LINEARFLAG = ISCOLINEAR(X) tests to see whether the 2-d points, X, lie
%   on a line.

%   Copyright 2006 The MathWorks, Inc.

% Ensure the first dimension of X is 2
sz = size(X);
if length(sz) > 2
    error(message('mbc:isColinear:InvalidArgument'));
end   
idxTwo = find(sz == 2);
if isempty(idxTwo)
    error(message('mbc:isColinear:InvalidArgument1'));
elseif length(idxTwo) == 1 && idxTwo == 2
    X = X';
end

% Test for colinearity by checking singular values from svd decomposition
Xm = sum(X,2)./size(X,2);
X(1,:) = X(1,:) - Xm(1);
X(2,:) = X(2,:) - Xm(2);
s = svd(X);
TOL = 100 * eps;
linearflag = s(1)==0 || s(2)/s(1) < TOL;