www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conswitch/merge.m
function c = merge(varargin) %MERGE merge xregmodswitch models and add mode variable to operating points % % c = merge(m1,m2,...mn); % c = merge(m1,m2,...mn,ModeVariable); % Copyright 2007 The MathWorks, Inc. if ischar(varargin{end}) ModeName = varargin{end}; n = nargin - 1; else ModeName = 'Mode'; n = nargin; end c = varargin{1}; nOpVars = size(c.OpPoints,2); if n>1 % no merging is required for one model ni = size(c.OpPoints,1); [cifMerge,cifGMerge]= iGetInputInfo(c,nOpVars); nf = length(cifMerge); af = repmat({1:nf},1,ni); OpPoints = [c.OpPoints ones(ni,1)]; ModelList = c.ConList; for i=2:n c = varargin{i}; ni = size(c.OpPoints,1); [cif,cifG]= iGetInputInfo(c,nOpVars); % find new variables [cifMerge,loc] = merge(cifMerge,cif); cifGMerge = merge(cifGMerge,cifG); % collect active factors af = [af repmat({loc},1,ni)]; % concatentate new operating points and mode OpPoints = [OpPoints ; c.OpPoints i*ones(ni,1)]; % concatenate models ModelList = [ModelList ; c.ConList]; end % add operating points variables cif = [cifMerge cifGMerge]; % Add mode variable cifMode = coninputfactor(ModeName,ModeName,'',1,n); cif = [cif cifMode]; % make new conswitch c = conswitch( cif ); % build new xregmodswitch c.ConList = ModelList; c.OpPoints = OpPoints; c.ActiveFactors = af; end function [cifL,cifG]= iGetInputInfo(m,nOpVars) cif = getInputFactors(m); cifL= cif(1:end-nOpVars); cifG= cif(end-nOpVars+1:end);