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

📄 nnexport.m

📁 神经网络预测控制程序的源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function nnexport(cmd,arg1,arg2,arg3)
%NNEXPORT Neural Network Export GUI for the Neural Network Controller Toolbox.
%
%  Synopsis
%
%    nnexport(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:10:52 $


% CONSTANTS
tag= 'Export_NN_Par_fig';

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

% FIND WINDOW IF IT EXISTS
fig=findall(0,'type','figure','tag',tag);
if (size(fig,1)==0), fig=0; end

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

if fig
   ud = get(fig,'userdata');
end

if strcmp(cmd,'init')
  if fig==0  
    StdColor = get(0,'DefaultFigureColor');
    PointsToPixels = 72/get(0,'ScreenPixelsPerInch');
    StdUnit = 'points';
    ud.Handles.parent=arg1;
    ud.Handles.type_net=arg2;

    if strcmp(ud.Handles.type_net,'nnpredict')
       me = 'Export Neural Network Plant Parameters';
    else
       me = 'Export Neural Network Plant-Controller Parameters';
    end
    
%---Open an Export figure
    fig = figure('Color',StdColor, ...
     'Interruptible','off', ...
     'BusyAction','cancel', ...
     'HandleVis','Callback', ...
    'MenuBar','none', ...
     'Visible','on',...
     'Name',me, ...
     'IntegerHandle','off',...
     'NumberTitle','off', ...
     'Resize', 'off', ...
     'WindowStyle','modal',...
     'Position',[193 127 305 250], ...
    'Tag',tag);

%---Add the Export List controls
    b = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
      'BackgroundColor',StdColor, ...
      'Position',PointsToPixels*[5 78 295 149], ...
     'Style','frame');
    b = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
      'BackgroundColor',StdColor, ...
    'Position',PointsToPixels*[106 215 56 19], ...
    'String','Select', ...
    'Style','text');
    ud.Handles.allv = uicontrol('Parent',fig, ...
      'Units',StdUnit, ...
    'BackgroundColor',StdColor, ...
     'Callback','nncontrolutil(''nnexport'',''allv'',gcbf);',...
    'ListboxTop',0, ...
    'Position',PointsToPixels*[14 188 120 20], ...
    'String','All Variables', ...
    'Style','radiobutton', ...
     'ToolTipStr','If selected, all variables of the neural network controller block will be exported.',...
     'Tag','Radiobutton1');
    if ~strcmp(ud.Handles.type_net,'nnpredict')
       ud.Handles.nncontrol = uicontrol('Parent',fig, ...
       'Units',StdUnit, ...
       'BackgroundColor',StdColor, ...
       'ListboxTop',0, ...
       'Position',PointsToPixels*[14 155 199 20], ...
       'String','Neural Network Controller Weights', ...
       'Style','radiobutton', ...
        'Tag','Radiobutton1', ...
        'ToolTipStr','If selected, the neural network controller weights will be exported.',...
        'Value',1);
       ud.Handles.nncontroledit = uicontrol('Parent',fig, ...
       'Units','points', ...
         'BackgroundColor',[1 1 1], ...
       'ListboxTop',0, ...
       'Position',PointsToPixels*[200 155 90 20], ...
       'String','netn_contr', ...
       'Style','edit', ...
        'ToolTipStr','You can select the name for the neural network controller object.',...
       'Tag','EditText1');
    end
    ud.Handles.nnplant = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'BackgroundColor',StdColor, ...
    'ListboxTop',0, ...
    'Position',PointsToPixels*[14 121 204 20], ...
    'String','Neural Network Plant Weights', ...
    'Style','radiobutton', ...
    'Tag','Radiobutton1', ...
     'ToolTipStr','If selected, the neural network plant weights will be exported.',...
     'Value',1);
    ud.Handles.nnplantedit = uicontrol('Parent',fig, ...
    'Units','points', ...
    'BackgroundColor',[1 1 1], ...
    'ListboxTop',0, ...
    'Position',PointsToPixels*[200 121 90 20], ...
    'String','netn_plant', ...
    'Style','edit', ...
     'ToolTipStr','You can select the name for the neural network plant object.',...
    'Tag','EditText1');
    ud.Handles.nnobject = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'BackgroundColor',StdColor, ...
     'Callback','nncontrolutil(''nnexport'',''obj_def'',gcbf);',...
    'ListboxTop',0, ...
    'Position',PointsToPixels*[14 88 204 20], ...
    'String','Use Neural Network Object Definition', ...
    'Style','checkbox', ...
    'Tag','checkbox1', ...
     'ToolTipStr','If selected, the neural network controller and plant will be exported using the network object definition, otherwise an independent variable will be created for each weight.',...
     'Value',1);

  %---Add the window buttons
    b = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'BackgroundColor',StdColor, ...
    'Position',PointsToPixels*[5 5 295 70], ...
    'Style','frame');
    ud.Handles.DiskButton = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'Position',PointsToPixels*[14 41 130 20], ...
     'Callback','nncontrolutil(''nnexport'',''disk'',gcbf);',...
    'String','Export to Disk', ...
     'ToolTipStr','Export the selected variables to a file.',...
    'Tag','DiskButton');
    ud.Handles.WorkspaceButton = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'Position',PointsToPixels*[14 14 130 20], ...
     'Callback','nncontrolutil(''nnexport'',''workspace'',gcbf);',...
    'String','Export to Workspace', ...
     'ToolTipStr','Export the selected variables to the MATLAB workspace.',...
    'Tag','WorkspaceButton');
    ud.Handles.SimulinkButton = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'Position',PointsToPixels*[160 41 130 20], ...
     'Callback','nncontrolutil(''nnexport'',''simulink'',gcbf);',...
    'String','Export to Simulink', ...
     'ToolTipStr','Export the selected variables into a new Simulink block (only valid for NN objects).',...
    'Tag','SimulinkButton');
    ud.Handles.HelpButton= uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
    'Position',PointsToPixels*[160 14 60 20], ...
     'Callback','nncontrolutil(''nnexport'',''windowstyle'',gcbf,''normal'');nncontrolutil(''nnexporthelp'',''main'',gcbf);',...
    'String','Help', ...
     'ToolTipStr','Call the Export Network help window.',...
    'Tag','HelpButton');
    ud.Handles.CancelButton = uicontrol('Parent',fig, ...
    'Units',StdUnit, ...
     'Position',PointsToPixels*[230 14 60 20], ...
     'Callback','nncontrolutil(''nnexport'',''cancel'',gcbf);',...
    'String','Cancel', ...
     'ToolTipStr','Discard the export action and close this menu.',...
    'Tag','CancelButton');

  end
  set(fig,'UserData',ud,'visible','on','WindowStyle','modal')
  
elseif strcmp(cmd,'cancel')
   delete(fig)
   return;
   
elseif strcmp(cmd,'windowstyle')
   set(fig,'visible','on','WindowStyle',arg2)
   return;
   
elseif strcmp(cmd,'obj_def')
   if get(ud.Handles.nnobject,'value')
      if ~strcmp(ud.Handles.type_net,'nnpredict')
         set(ud.Handles.nncontroledit,'enable','on');
      end
      set(ud.Handles.nnplantedit,'enable','on');
      set(ud.Handles.SimulinkButton,'enable','on');
   else
      if ~strcmp(ud.Handles.type_net,'nnpredict')
         set(ud.Handles.nncontroledit,'enable','off');
      end
      set(ud.Handles.nnplantedit,'enable','off');
      set(ud.Handles.SimulinkButton,'enable','off');
   end
   
elseif strcmp(cmd,'allv')
    allv=get(ud.Handles.allv,'value');
    if allv
       if ~strcmp(ud.Handles.type_net,'nnpredict')
          set(ud.Handles.nncontrol,'enable','off');
       end
       set(ud.Handles.nnplant,'enable','off');
    else
       if ~strcmp(ud.Handles.type_net,'nnpredict')
          set(ud.Handles.nncontrol,'enable','on');
       end
       set(ud.Handles.nnplant,'enable','on');
    end
    
elseif strcmp(cmd,'workspace') | strcmp(cmd,'simulink') | strcmp(cmd,'disk')
    % We check if some option selected.
   allv=get(ud.Handles.allv,'value');
   if ~strcmp(ud.Handles.type_net,'nnpredict')
      nnco=get(ud.Handles.nncontrol,'value');
   else
      nnco=0;
   end
   nnpl=get(ud.Handles.nnplant,'value');
   if allv==0 & nnco==0 & nnpl==0,
      warndlg('There are no variables to export.','Export Warning','modal');
      return      
   end
   
   overwrite=0;
   w = evalin('base','whos');
   Wname = {w.name};
   
   nnob=get(ud.Handles.nnobject,'value');
   
   figure_variables=get(ud.Handles.parent,'userdata');
   parent_simulink=get(figure_variables.gcbh_ptr,'userdata');
      
   % We check for Controller and object structure.
   if (nnco | nnpl | allv) & nnob
      mint=str2num(get_param(parent_simulink,'mint'));
      maxt=str2num(get_param(parent_simulink,'maxt'));
      minp=str2num(get_param(parent_simulink,'minp'));
      maxp=str2num(get_param(parent_simulink,'maxp'));
      Nj=str2num(get_param(parent_simulink,'Nj'));
      Ni=str2num(get_param(parent_simulink,'Ni'));
  
      S2=1;
      f1 = 'tansig';
      f2 = 'purelin';
      if strcmp(ud.Handles.type_net,'narma_l2')
         S1=str2num(get_param(parent_simulink,'S1'));
         
         IW1_1=eval(strvcat(get_param(parent_simulink,'IW1_1')));
         IW3_2=eval(strvcat(get_param(parent_simulink,'IW3_2')));
         IW5_3=eval(strvcat(get_param(parent_simulink,'IW5_3')));
         LW2_1=eval(strvcat(get_param(parent_simulink,'LW2_1')));
         LW4_3=eval(strvcat(get_param(parent_simulink,'LW4_3')));
         LW5_4=eval(strvcat(get_param(parent_simulink,'LW5_4')));
         LW6_5=eval(strvcat(get_param(parent_simulink,'LW6_5')));
         LW6_2=eval(strvcat(get_param(parent_simulink,'LW6_2')));
         B1=eval(strvcat(get_param(parent_simulink,'B1')));

⌨️ 快捷键说明

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