www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcmodel/@response/pSetModel.m
function val = pSetModel(R, val) %PSETMODEL Private function. % % VAL = PSETMODEL( RESP, VAL ) % Copyright 2004-2006 The MathWorks, Inc. M = val; mdev = R.Object; mod = M.Object; % Is the model going back in the same place? This is a limitation that % should be removed when we can asscertain if the model is of the correct % type to site here. Generally this should be a check that the number of % factors and model class are suitable for this node if isempty(M.Response) || (R ~= M.Response) error('mbc:mbcmodel:response:InvalidState', ... 'A model can only be replaced on the same node of a project as it originated.'); end % Cannot change a model of a response if it has children if numChildren(mdev) > 0 error(message('mbc:mbcmodel:response:InvalidState4')); end % Need to check if the respose is a mdevmlerf - these cannot have their % models changed. Really ought to have a way of asking the OOP object if it % will accept a new model but this doesn't currently exist if isa(mdev, 'mdevmlerf') error(message('mbc:mbcmodel:response:InvalidState5')); end % Has the data that the model is fitted to changed? This could be either % because a user has called Fit on the model, or that the testplan or % response data has been changed (new data attached or outliers removed) [Xm, Ym] = pGetData(M); [Xrs, Yrs, OK] = FitData(mdev); Xr = double(Xrs(OK, :)); Yr = double(Yrs(OK, :)); DATA_IDENTICAL = isequaln(Xm, Xr) && isequaln(Ym, Yr); % pGetModelStatus allows us access to the private ModelStatus method so we % can get the numeric status that we need for the later call to % modeldev/status. modelStatus = M.pGetModelStatus(); % Is the model currently fitted to it's data MODEL_FITTED = modelStatus ~= 0; if DATA_IDENTICAL && MODEL_FITTED % Copy back to modeldev mdev = model(mdev, mod); % Calculate summary stats [Xm, Ym] = checkdata(mod, Xm, Ym); mod = InitModel(mod,Xm,Ym); S = FitSummary(mod, Xm, Ym); mdev = statistics(mdev, S); % copy fit status mdev = status(mdev, modelStatus); else % need a full fit mdev = model(mdev, mod); fitmodel(mdev); end % Store nothing in the response val = [];