⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nnpredict.m

📁 RBF网络逼近、RBF-建模、RBF网络训练与测试程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function nnpredict(cmd,arg1,arg2,arg3)
%NNPREDICT Neural Network Predictive Controller GUI for Neural Network Controller Toolbox.
%
%  Synopsis
%
%    nnpredict(cmd,arg1,arg2,arg3)
%
%  Warning!!
%
%    This function may be altered or removed in future
%    releases of the Neural Network Toolbox. We recommend
%    you do not write code which calls this function.
%    This function is generally being called from a Simulink block.

% Orlando De Jesus, Martin Hagan, 1-25-00
% Copyright 1992-2002 The MathWorks, Inc.
% $Revision: 1.5 $ $Date: 2002/04/14 21:11:28 $


% CONSTANTS
me = 'Neural Network Predictive Control';

% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); end

% FIND WINDOW IF IT EXISTS
fig = 0;

% 9/3/99 We alow the program to see hidden handles
fig=findall(0,'type','figure','name',me);
if (size(fig,1)==0), fig=0; end

if length(get(fig,'children')) == 0, fig = 0; end

% GET WINDOW DATA IF IT EXISTS
if fig
  H = get(fig,'userdata');
  
  if strcmp(cmd,'')
    if get(H.gcbh_ptr,'userdata')~=arg1
      delete(fig);
      fig=0;
    end
  else
     % ODJ 1-13-00 We check if the field SimulationStatus exist before reading that field
    if isfield(get(H.gcbh_ptr,'userdata'))
       if isfield(get_param(get_param(get(H.gcbh_ptr,'userdata'),'parent'),'objectparameters'),'SimulationStatus')
          SimulationStatus=get_param(get_param(get(H.gcbh_ptr,'userdata'),'parent'),'SimulationStatus');
       else
          SimulationStatus='none';
       end
    else
       SimulationStatus='none';
    end
    if (strcmp(SimulationStatus,'running') | strcmp(SimulationStatus,'paused')) & ~strcmp(cmd,'close')
      set(H.error_messages(1,1),'string','You must stop the simulation to change NN configuration parameters.');
      return;
    end
  end
end

%==================================================================
% Activate the window.
%
% ME() or ME('')
%==================================================================

if strcmp(cmd,'')
  if fig
    figure(fig)
    set(fig,'visible','on')
  else
    nncontrolutil('nnpredict','init',arg1,arg2);
  end

%==================================================================
% Close the window.
%
% ME() or ME('')
%==================================================================

elseif strcmp(cmd,'close') & (fig)
   delete(fig)
   return;

elseif (strcmp(cmd,'apply') | strcmp(cmd,'ok')) & (fig)
  arg1=get(H.gcbh_ptr,'userdata');
  
  a1 = str2num(get(H.N2_edit,'string'));
  if length(a1) == 0, a1=0; end
  if a1<2,
     N2=get_param(arg1,'N2'); 
     present_error(H,H.N2_edit,N2,1, ...
         'Please, correct the cost horizon value (N2)'); 
     return
  else set_param(arg1,'N2',num2str(a1)); end
  
  a1 = str2num(get(H.Nu_edit,'string'));
  if length(a1) == 0, a1=0; end
  if a1<2,
     Nu=get_param(arg1,'Nu'); 
     present_error(H,H.Nu_edit,Nu,1, ...
         'Please, correct the control horizon value (Nu)'); 
     return
  else set_param(arg1,'Nu',num2str(a1)); end
    
  a1 = str2num(get(H.rho_edit,'string'));
  if length(a1) == 0,
     rho=get_param(arg1,'rho'); 
     present_error(H,H.rho_edit,rho,1, ...
         'Please, correct the control weighting factor'); 
     return
  else set_param(arg1,'rho',num2str(a1)); end
    
  a1 = str2num(get(H.alpha_edit,'string'));
  if length(a1) == 0,
     alpha=get_param(arg1,'alpha');
     present_error(H,H.alpha_edit,alpha,1, ...
         'Please, search parameter'); 
     return
  else set_param(arg1,'alpha',num2str(a1)); end
    
  func_index=['csrchgol';'csrchbac';'csrchhyb';'csrchbre';'csrchcha'];
  a1 = get(H.csrchfun_edit,'value');
  if (a1 < 1) | (a1 > 5), 
     csrchfun=get_param(arg1,'csrchfun'); 
     a1=strmatch(csrchfun,func_index);
     set(H.csrchfun_edit,'value',a1);
     present_error(H,H.csrchfun_edit,a1,0, ...
        'Please, correct the minimization function'); 
     return
  else set_param(arg1,'csrchfun',func_index(a1,:)); end
    
  a1 = str2num(get(H.maxiter_edit,'string'));
  if length(a1) == 0, a1=0; end
  if a1<1,
     maxiter=get_param(arg1,'maxiter');
     present_error(H,H.maxiter_edit,maxiter,1, ...
         'Please, correct the number of iterations per sample time'); 
     return
  else set_param(arg1,'maxiter',num2str(a1)); end
    
  if strcmp(cmd,'ok')
     delete(fig)
  else
    set(H.error_messages(1,1),'string',sprintf(' '));
  end
  
%==================================================================
% Execute Training.
%
% ME('training')
%==================================================================

elseif strcmp(cmd,'training') & (fig)
  arg1=get(H.gcbh_ptr,'userdata');
  arg2=get(H.gcb_ptr,'userdata');
  nnident('',arg1,arg2,'nnpredict');

%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================

elseif strcmp(cmd,'init') & (~fig)

  % 1-13-00 ODJ We check if the system is locked.
  sys_par=arg2;
  sys_par2=arg2;
  while ~isempty(sys_par2)
      sys_par=sys_par2;
      sys_par2=get_param(sys_par,'parent');
  end
  if strcmp('on',get_param(sys_par,'lock'))
      window_en='off';
  else
      window_en='on';
  end

  fig = figure('CloseRequestFcn','nncontrolutil(''nnpredict'',''close'')', ...
   'Interruptible','off', ...
   'BusyAction','cancel', ...
   'HandleVis','Callback', ...
   'Color',[0.8 0.8 0.8], ...
  'MenuBar','none', ...
   'Name',me, ...
   'numbertitle','off', ...
   'IntegerHandle',  'off',...
  'PaperUnits','points', ...
  'Position',[39 26 480 297], ...
  'Tag','Fig4', ...
  'ToolBar','none');
  frame1 = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.8 0.8 0.8], ...
  'ListboxTop',0, ...
  'Position',[5 64 350 23], ...
  'Style','frame', ...
  'Tag','Frame1');
  frame2 = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.8 0.8 0.8], ...
  'ListboxTop',0, ...
  'Position',[5 89 164 60], ...
  'Style','frame', ...
  'Tag','Frame2');
  frame3 = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.8 0.8 0.8], ...
  'ListboxTop',0, ...
  'Position',[171 89 184 60], ...
  'Style','frame', ...
  'Tag','Frame3');
  H.Title_nnpredict = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.8 0.8 0.8], ...
  'FontSize',14, ...
  'ListboxTop',0, ...
  'Position',[30 171.75 300 21.75], ...
  'String','Neural Network Predictive Control', ...
  'Style','text', ...
  'Tag','Title_nnpredict');
  frame4 = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.8 0.8 0.8], ...
  'ListboxTop',0, ...
  'Position',[5 36 350 26], ...
  'Style','frame', ...
  'Tag','Frame4');
  H.Train_NN = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
  'Callback','nncontrolutil(''nnpredict'',''training'');', ...
    'Enable',window_en, ...
  'ListboxTop',0, ...
  'Position',[15 41 90 15], ...
  'String','Plant Identification', ...
  'ToolTipStr','Opens a window where you can develop the neural network plant model.',...
  'Tag','Pushbutton1');
  H.OK_but = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
  'Callback','nncontrolutil(''nnpredict'',''ok'')', ...
    'Enable',window_en, ...
  'ListboxTop',0, ...
  'Position',[125 41 60 15], ...
  'String','OK', ...
   'ToolTipStr','Save the parameters into the neural network controller block and close this window.',...
  'Tag','OK_but');
  H.Cancel_but = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
  'Callback','nncontrolutil(''nnpredict'',''close'')', ...
  'ListboxTop',0, ...
  'Position',[205 41 60 15], ...
  'String','Cancel', ...
   'ToolTipStr','Discard the neural network controller parameters.',...
  'Tag','Pushbutton1');
  H.Apply_but = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[0.752941176470588 0.752941176470588 0.752941176470588], ...
  'Callback','nncontrolutil(''nnpredict'',''apply'')', ...
    'Enable',window_en, ...
  'ListboxTop',0, ...
  'Position',[285 41 60 15], ...
  'String','Apply', ...
   'ToolTipStr','Save the parameters into the neural network controller block.',...
  'Tag','Apply_but');
  H.N2_edit = uicontrol('Parent',fig, ...
  'Units','points', ...
  'BackgroundColor',[1 1 1], ...
    'Enable',window_en, ...
  'ListboxTop',0, ...
  'Position',[120 130.5 45 15], ...
  'String','', ...
  'Style','edit', ...
   'ToolTipStr','Cost horizon value for the set-point error.',...
  'Tag','N2_edit');
  H.N2_text = uicontrol('Parent',fig, ...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -