www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcmodel/@model/CreateModel.m
function MdlNew = CreateModel(mdl,Type) %CREATEMODEL create a new model with the same inputs as mdl % % NEWMODEL = CREATEMODEL(MODEL,Type); % You can get a list of valid types with % MBCMODEL.MODEL.GETALTERNATIVETYPES % % See also mbcmodel.model.getAlternativeTypes, mbcmodel/CreateModel, % mbcmodel.model.ModelSetup % Copyright 2006-2015 The MathWorks, Inc. m = mdl.Object; % get list of models constructors (option 8 means expand linear models) mc = ModelClasses(m,8); % remove spaces from Type Type = strrep(Type,' ',''); if isa(m,'localmod') Prefix = 'Local '; else Prefix = ''; end nModels = length(mc.fCreate); OK = false; for i=1:nModels try % create xregmodel mnew = xregCreateModel(mc.fCreate{i},m); % copy base model info if strcmp(strrep([Prefix getType(mnew)],' ',''),Type) OK = true; break end end end if ~OK && strcmpi(Type,'LocalMultipleModels') || strcmpi(Type,'Point-by-Point') % compatibility for point-by-point mnew = xregCreateModel(@localmulti,m); OK = true; end if OK % create command-line model MdlNew = mbcmodel.CreateModel(mnew); % copy data and response MdlNew.data = mdl.data; MdlNew.Response = mdl.Response; else List = getAlternativeTypes(mdl); ListString = sprintf('''%s'',',List{:}); ListString(end)= '.'; error(message('mbc:mbcmodel:model:InvalidArgument1', ListString)) end