www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@mdevtestplan/Export2CAGE.m
function [pNode,rep] = Export2CAGE(T,CGP,ImportItems,doReplace,doReplaceVars) %EXPORT2CAGE % % [pNode,rep] = Export2CAGE(T,CGP,Items,doReplace,doReplaceVars) % Copyright 2007-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. % $Revision: 1.1.8.1.2.2 $ $Date: 2013/10/09 06:28:55 $ if nargin<4 || isempty(doReplace) doReplace = false; end if nargin<5 || isempty(doReplaceVars) doReplaceVars = true; end pList = ImportItems.Items; names = ImportItems.Names; n = length(names); pNode = mbcpointer(1, 0); rep = false(1,0); mdls = pveceval(pList,@getBestExportModel); [mdls{:}]= shareConstraints(mdls{:}); % make variables for all inputs so we don[t recreate them each time % (with potentially different names) if n>0 [pInputs,IsNew] = ModelInputs(info(CGP),mdls{1}, doReplaceVars,true); end for i=1:n % export each model newnames = names{i}; if ~iscell(newnames) newnames = {newnames}; end for j=1:length(newnames) % there might be multiple models to replace try pModInputs = iSelectInputs(mdls{i},pInputs); [pNode(end+1),rep(end+1)] = ImportMBCModel(info(CGP),mdls{i},newnames{j},doReplace(i),doReplaceVars,pModInputs); end end end % remove new and unused inputs from project A= UpdateConnections(info(CGP)); for i=1:length(pInputs) if IsNew(i) pos = find(A.pData==pInputs(i)); if isempty(getAllUsers(A,pos)) A = delete(A,pos); end end end function pInputs = iSelectInputs(m,pInputs) % pInputs can be supplied by the test plan for all inputs nf = nfactors(m); if nf<length(pInputs) if isa(model(m),'localmod') pInputs = pInputs(1:nf); else pInputs = pInputs(end-nf+1:end); end end