www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/cgindependentvars.m
function [pOut, pReject] = cgindependentvars(pIn) %CGINDEPENDENTVARS Shorten a list of variables to only independent ones % % P_OUT = CGINDEPENDENTVARS(P_IN) returns only those pointer in PIN which % point to independent variables. Variables are non-independent when % their values are linked via formulas. The simple case of this is when % PIN contains a variable and formula that depends on that variable. More % complex cases can arise - for example two formulas that depend on the % same variable that is not in P_IN. % % [P_OUT, P_LOST] = CGINDEPENDENTVARS(P_IN) also returns the list of % pointers that have been removed. % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. % use doubles to check because of speed considerations pCheck = double(pIn); isdep = false(size(pCheck)); objVar = infoarray(pIn); for n = 1:numel(isdep) if issymvalue(objVar{n}) % Replace formulae with the variable they are using for checking % purposes pCheck(n) = double( getvariable(objVar{n}) ); end isdep(n) = ismember(pCheck(n), pCheck(1:n-1)); end pOut = pIn(~isdep); if nargout>1 pReject = pIn(isdep); end