www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@coninputfactor/p_Match.m
function index = p_Match(cifA, cifB) %P_MATCH Match two sets of input factors % % I = P_MATCH(CIFA, CIFB) % % The output I is the indices into B that A matches to, i.e., A is matched to % B(I). The size of I is the same as the size of A. For any unmatched factors, % I will be zero. % % This is a non-interactive matcher. It makes a best guess at the matches % between the two sets of inputs. Use GUIMATCH for an interactive version. % % Algorithm % ========= % Precedence is determined by the storage order as a last resort % -- If any names match exactly, then match those two factors. % -- If any symbols match exactly, then match those two factors. % -- Take the closest name in B to A. % % See also CONINPUTFACTOR, CONINPUTFACTOR/GUIMATCH. % Copyright 2004-2015 The MathWorks, Inc. if nargin < 2 || ~isa( cifA, 'coninputfactor' ) || ~isa( cifB, 'coninputfactor' ), error(message('mbc:coninputfactor:InvalidArguments10')); end if length( cifA ) > length( cifB ), error(message('mbc:coninputfactor:InvalidArguments11')); end % Flags to indicate that factor from A is matched matched = false( size( cifA ) ); % Allocate space for matching indices index = zeros( size( cifA ) ); aName = cifA.Name; bName = cifB.Name; % Try exact matches on names [tf, loc] = ismember( aName, bName ); if any( tf ), matched = tf; index(tf) = loc(tf); end aSymbol = cifA.Symbol; bSymbol = cifB.Symbol; % Try exact matches on symbols [tf, loc] = ismember( aSymbol, bSymbol ); tf(matched) = false; if any( tf ), index(tf) = loc(tf); matched = matched | tf; end notMatchedAInd = find(~matched); notMatchedBInd = setdiff(1:length(bSymbol), index); remainingInds = mbcMatchNames(aSymbol(notMatchedAInd), bSymbol(notMatchedBInd), 'MatchLevel', 0); index(notMatchedAInd) = notMatchedBInd(remainingInds);