www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgexprgroup/getRequiredInputs.m

    function ReqInd = getRequiredInputs(obj, ItemInd)
%GETREQUIREDINPUTS Get the inputs that are required for outputs.
%
%   REQIND = GETREQUIREDINPUTS(OBJ, ITEMIND) finds the inputs that are
%   required for the evaluations of the items at ITEMIND in the expression
%   list.  REQIND is a cell array the same length as ITEMIND with each cell
%   containing the inputs required for the corresponding item.  The input
%   indices that are returned are indices into the list of input values
%   that are expected in the evaluate command - they are not indices into
%   the expression list.
%
%   If ITEMIND is omitted, the input requirements of all the outputs will
%   be returned.

%   Copyright 2005-2009 The MathWorks, Inc.


if nargin<2 || isequal(ItemInd,obj.Outports)
    ReqInd = obj.OutportRequiredIndices;
else
    [IsCachedOut, CachedOutIdx] = ismember(ItemInd, obj.Outports);
    if all(IsCachedOut)
        ReqInd = obj.OutportRequiredIndices(CachedOutIdx);
    else
        ReqInd  = cell(size(ItemInd));
        ReqInd(IsCachedOut) = obj.OutportRequiredIndices(CachedOutIdx(IsCachedOut));
        ReqInd(~IsCachedOut) = pGetEvaluationIndices(obj.InputIndices, ItemInd(~IsCachedOut));
    end
end

% Go through the required indices and pick out the indices of the input
% ones in the list of expected inputs
InpIdx = obj.Inports;
for n = 1:length(ReqInd)
    [IsInp, InpLoc] = ismember(ReqInd{n}, InpIdx);
    ReqInd{n} = InpLoc(IsInp);
end