www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgproject/ImportMBCModel.m
function [pCAGE,doReplace] = ImportMBCModel(CGP,m,name,doReplace,doReplaceVars,pInputs) %Export2CAGE Export model to CAGE. % % Throws an error in the event of failure. % % [pCAGE,Replaced] = ImportMBCModel(CGP,m); % [pCAGE,Replaced] = ImportMBCModel(CGP,m,name); % [pCAGE,Replaced] = ImportMBCModel(CGP,m,name,replace,doUpdateVars,pInputs); % CGP : CAGE project (pointer to cgproject or file name) % m : xregstatsmodel % name : Name of model node to create. If a model with this name % exists in the CAGE project it can be replaced (depending % on the value of the next parameter). However, if % a node of any other type exists with this name, or if the % existing model node has the wrong number of inputs, and error % will be thrown. % replace : true if any existing model of the same name should be replaced. % The default is false, in which case an error is thrown if a % model of the same name already exists. % doUpdateVars: update variable ranges in CAGE % pInputs : supplied list of inputs to CAGE model. These inputs are % only used if a new model is created % Copyright 2006-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<3 || isempty(name) name = getname(m); elseif iscell(name) name = name{1}; end if nargin<4 doReplace = true; end if nargin<5 doReplaceVars = true; end if nargin<6 pInputs = []; end % find existing node in project pModnode= findname(CGP,name); doReplace= doReplace && ~isempty(pModnode) && pModnode.isa('cgmodelnode'); if doReplace pMod = pModnode.getdata; % has same number of inputs doReplace = pMod.nfactors == nfactors(m); end if doReplace pMod = pModnode.getdata; % replace model inside the cgmodexpr pMod.info = pMod.set('model',m); if doReplaceVars pInp= pMod.getinputs; R = getranges(m); for i=1:length(pInp) if isa(pInp(i).info,'cgvalue') % update ranges for variables pInp(i).info= setrange(pInp(i).info,R(:,i)'); end end end else % make new model expression pMod= xregpointer( cgmodexpr(name,m) ); % make new model node pModnode = cgnode(pMod.info,pMod,pMod,0); if isempty(pInputs) % add variables to data dictionary pInputs = ModelInputs(info(CGP),m, doReplaceVars,true); end pMod.info = pMod.setinputs(pInputs); % Change above, so unique names are given to models addnodestoproject(CGP, pModnode); end % otherwise, the CAGE model view may need to be refreshed by the caller pCAGE= pModnode;