www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregmodswitch/getSwitchGrid.m
function gridOK = getSwitchGrid(m, varargin) %GETSWITCHGRID Generate a logical grid of valid sites % % GRID = GETSWITCHGRID(M, X1, X2, ..., Xn) where X1...Xn are vectors of % input values for each switch input factor returns a logical grid of size % (length(X1)-by-length(X2)-by-...-by-length(Xn)) that contains true % values at the positions where there is a valid evaluation point. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. swFact = getSwitchFactors(m); if length(varargin)~=length(swFact) error(message('mbc:xregmodswitch:InvalidArgument1')); end dims = cellfun('length', varargin); % find switch factors in the grid GridDims = find(dims>1); sliceDims = ones(size(dims)); sliceDims(GridDims) = dims(GridDims); sliceOK = false(sliceDims); gridcell = cell(1, length(GridDims)); switch length(GridDims) case 0 % no grid dimensions are switch factors case 1 % ndgrid for one argument still makes 2 dimensional grid so don't call % ndgrid gridcell{GridDims} = varargin{GridDims}; otherwise % use ndgrid for two or more factors [gridcell{GridDims}] = ndgrid(varargin{GridDims}); end if any(dims==1) % fill in scalar values; gridcell(dims==1) = varargin(dims==1); end checkPts = zeros(numel(sliceOK), nfactors(m)); for n = 1:length(GridDims) ind=swFact(GridDims(n)); checkPts(:,ind) = gridcell{n}(:); end sliceOK(:) = isSwitchPoint(m, checkPts); gridOK = sliceOK;