www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregmodswitch/isSwitchPoint.m

    function ret = isSwitchPoint(m, X,dims)
%ISSWITCHPOINT Check whether a point is a valid evaluation site
%
%  RET = ISSWITCHPOINT(M, X) where X is a (nPoints-by-nFactors) matrix of
%  evaluation points returns a logical vector of length nPoints containing
%  true where the corresponding evaluation point is a valid evaluation site
%  for the switched model.

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


nf = nfactors(m);
if size(X, 2)~=nf
    error(message('mbc:xregmodswitch:InvalidArgument'));
end

[nPoints,ng] = size(m.OpPoints);
nCheckPts = size(X, 1);
swFact = getSwitchFactors(m);
if nargin>2
    swFact = intersect(swFact,dims);
    dims=dims-(nf-ng);
else
    dims = swFact-(nf-ng);
end
if any(dims<1)
    ret = true(nCheckPts, 1);
    return
end    
% tolerance for comparison
tol = repmat(getAbsoluteTolerance(m), nPoints, 1);
switchPts = m.OpPoints(:,dims);
tol = tol(:,dims);
ng = size(switchPts,2);
ret = false(nCheckPts, 1);
checkExp = switchPts;
for n = 1:nCheckPts
    for k = 1:ng
        % Avoid repmat within the loop so everything is JITed
        checkExp(:,k) = X(n , swFact(k));
    end
    ret(n) = any(all(abs(checkExp - switchPts) < tol, 2));
end