www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepset/isEquiSpaced.m

    function ret = isEquiSpaced(X,tol)
%ISEQUISPACED Check whether first column of X is equispaced within sweeps
%
%  ISEQUISPACED(X, TOL) returns 0 if the first column of X is not
%  equispaced and the data is increasing 
%
%     the spacing value if it is equispaced otherwise zero is returned

%  Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc.

d1 = diff(X.data(:,1));

if nargin<2
   tol = mean(abs(d1))*1e-4;
end

s = tsizes(X);
s(s<=1) = [];

% delete last element in each sweep
d1(cumsum(s(1:end-1))) = [];
d2 = diff(d1);
s(s<=2) = [];

d2(cumsum(s(1:end-1)-1)) = [];
% second difference should be zero and first difference should be positive
ok = all(abs(d2-mean(d2))<tol) && all(d1>0);
if ok
    ret = mean(d1);
else
    ret = 0;
end