www.gusucode.com > sloptim工具箱matlab源码程序 > sloptim/sloptguis/@srocsdgui/@tunedparameterpnl/evalForm.m

    function [pSpec,model] = evalForm(this) 
% EVALFORM  method to return parameters to use in runtime optimization from
% GUI
%
 
% Author(s): A. Stothert 08-Sep-2005
% Copyright 2005-2007 The MathWorks, Inc.

%Update the model api to make sure all parametrs are up-to-date
model   = this.Data.Model;
model.update
%Create empty vector of parameters to optimize
pSpec = [];

%Use the table to find parameters that are selected for optimization.
%Be careful of zpk gain parameters as we need to set their format to
%'Invariant'
h        = this.JavaHandle;   %Handle to java table
rowCount = h.getTable.getRowCount;
CompIdx  = double(h.getCompensatorIndices)+1;
idxP     = this.idxData.idxP;     %Compensators dispalayed as parameters
for ct=1:rowCount
   if any(CompIdx==ct)
      %Working with compensator row, reset indices
      idxComp  = find(CompIdx==ct);
      idxParam = 1;
   else
      %Working with a parameter row
      pTemp = findParameter(this,idxComp,idxParam);
      if ~pTemp.pSpec.Known
         if ~idxP(idxComp) && idxParam==1
            %Have a zpk gain parameter spec, set format to 'Invariant'
            addP = copy(pTemp.pSpec);
            addP.setFormat(model,'Invariant');
         else
            %Standard parameter spec
            addP = pTemp.pSpec;
         end
         pSpec = [pSpec;addP];
      end
      %Bump parameter index
      idxParam = idxParam+1;
   end
end

%Check that we have at least one parameter to optimize
if isempty(pSpec)
   ctrlMsgUtils.error('Sloptim:srosisotool:errNoCompensatorsToOptimize');
end

%Check that all parameters, and initial values are real
initValue = get(pSpec,'InitialValue');
if ~iscell(initValue), initValue = {initValue}; end
currValue = this.Data.model.getValue(pSpec);
currValue = get(currValue,'Value');
if ~iscell(currValue), currValue = {currValue}; end
if any(~cellfun(@(x) isreal(x), initValue)) || ...
     any(~cellfun(@(x) isreal(x), currValue)) 
  ctrlMsgUtils.error('Sloptim:srosisotool:errOptimComplexVar')
end