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

📄 mfedit.m

📁 最新模糊逻辑工具箱
💻 M
📖 第 1 页 / 共 4 页
字号:
function mfedit(action,varType,varIndex);
%MFEDIT Membership function editor.
%   The Membership Function (MF) Editor is used to create, 
%   remove, and modify the MFs for a given fuzzy system. On 
%   the left side of the diagram is a "variable palette" 
%   region that you use to select the current variable by 
%   clicking once on one of the displayed boxes. Information   
%   about the current variable is displayed in the text region 
%   below the palette area.
%
%   To the right is a plot of all the MFs for the current 
%   variable. You can select any of these by clicking once on 
%   the line or name of the MF. Once selected, you can modify 
%   the properties of the MF using the controls in the lower right.  
%   MFs are added and removed using the Edit menu.    
%
%   See also 
%       fuzzy, ruleedit, ruleview, surfview, anfisedit

%   Kelly Liu 6-26-96 Ned Gulley, 4-30-94
%   Copyright (c) 1994-98 by The MathWorks, Inc.
%   $Revision: 1.51 $  $Date: 1997/12/01 21:45:08 $

if get(0,'ScreenDepth')>2,
   figColor=[0.9 0.9 0.9];
   selectColor=[1 0 0];
   unselectColor=[0 0 0];
   inputColor=[1 1 0.8];
   outputColor=[0.8 1 1];
else
   figColor=[1 1 1];
   selectColor=[0 0 0.1];
   unselectColor=[0 0 0.1];
   inputColor=[1 1 1];
   outputColor=[1 1 1];
end

if nargin<1,
   newFis=newfis('Untitled');
   newFis=addvar(newFis,'input','input1',[0 1]);
   newFis=addvar(newFis,'output','output1',[0 1]);
   action=newFis;
end

if isstr(action),
   if action(1)~='#',
      % The string "action" is not a switch for this function, 
      % so it must be a disk file
      fis=readfis(action);
      action='#initialize';
   end
else
   % For initialization, the fis matrix is passed in as the parameter
   fis=action;
   action='#initialize';
end;

if strcmp(action,'#initialize'),
   fisName=fis.name;
   fisType=fis.type;

    if isfield(fis, 'input')
      numInputs=length(fis.input);
    else
      numInputs=0;
    end

    if isfield(fis, 'output')
      numOutputs=length(fis.output);
    else
      numOutputs=0;
    end
    if isfield(fis, 'rule')
      numRules=length(fis.rule);
    else
      numRules=0;
    end
   
   %===================================
   % Information for all objects
   frmColor=192/255*[1 1 1];
   btnColor=192/255*[1 1 1];
   popupColor=192/255*[1 1 1];
   editColor=255/255*[1 1 1];
   border=6;
   spacing=6;
   figPos=get(0,'DefaultFigurePosition');
   maxRight=figPos(3);
   maxTop=figPos(4);
   btnWid=100;
   btnHt=22;
   
   %====================================
   % The FIGURE
   thisfis{1}=fis;
   figNumber=figure( ...
      'Name',['Membership Function Editor: ' fisName], ...
      'NumberTitle','off', ...
      'Visible','off', ...
      'Color',figColor, ...
      'MenuBar','none', ...
      'UserData',thisfis, ...
      'Position',figPos, ...
      'KeyPressFcn','mfedit #keypress', ...
      'DefaultAxesFontSize',8, ...
      'Tag','mfedit', ...
      'DoubleBuffer', 'on', ...
      'BackingStore','off');
   figPos=get(figNumber,'position');
   
   %====================================
   % The MENUBAR items
   % First create the menus standard to every GUI
   fisgui #initialize
   
   editHndl=findobj(figNumber,'Type','uimenu','Tag','editmenu');
   uimenu(editHndl,'Label','Add MFs...', ...
      'Callback','mfedit #addmfs');
   uimenu(editHndl,'Label','Add custom MF...', ...
      'Tag','addcustommf', ...
      'Callback','mfedit #addcustommf');
   uimenu(editHndl,'Label','Remove current MF', ...
      'Tag','removemf', ...
      'Enable','off', ...
      'Callback','mfedit #removemf');
   uimenu(editHndl,'Label','Remove all MFs', ...
      'Tag','removeallmf', ...
      'Callback','mfedit #removeallmfs');
   uimenu(editHndl,'Label','Undo', ...
      'Separator','on', ...
      'Enable','off', ...
      'Tag','undo', ...
      'Callback','popundo(gcf)');
   
   %====================================
   % The MAIN frame 
   top=(maxTop)*0.47;
   bottom=border; 
   right=maxRight-border;
   left=border;
   frmBorder=spacing;
   frmPos=[left-frmBorder bottom-frmBorder ...
         right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
   
   %====================================
   % The MAIN axes
   tickColor=[0.5 0.5 0.5];
   axBorder=40;
   axPos=[left+axBorder+(right-left)/5 top+axBorder ...
         4/5*(right-left)-1.5*axBorder maxTop-top-border-1.5*axBorder];
   btnDownFcn='mfedit #deselectmf';
   param.CurrMF=-1;
   param.Action='';
   mainAxHndl=axes( ...
      'Units','pixel', ...
      'XColor',tickColor,'YColor',tickColor, ...
      'Color',inputColor, ...
      'Position',axPos, ...
      'Tag','mainaxes', ...
      'Userdata', param, ...
      'ButtonDownFcn',btnDownFcn, ...
      'Box','on');
   titleStr='Membership function plots';
   title(titleStr,'Color','black');
   
   %====================================
   % The VARIABLE PALETTE axes
   axBorder=5;
   axPos=[left+axBorder top+2*axBorder ...
         1/5*(right-left)-1.5*axBorder maxTop-top-border-7*axBorder];
   axHndl=axes( ...
      'Units','pixel', ...
      'Visible','off', ...
      'XColor',tickColor,'YColor',tickColor, ...
      'Position',axPos, ...
      'Tag','variables', ...
      'Box','on');
   axes(mainAxHndl)
   %draw frame
   mainFrmHndl=uicontrol( ...
      'Style','frame', ...
      'Units','pixel', ...
      'Position',frmPos, ...
      'BackgroundColor',frmColor);
   %====================================
   % The VARIABLE frame 
   top=top-spacing;
   bottom=border+4*spacing+btnHt;
   left=border+spacing;
   right=left+2*btnWid+spacing;
   frmBorder=spacing;
   frmPos=[left-frmBorder bottom-frmBorder ...
         right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
   varFrmHndl=uicontrol( ...
      'Style','frame', ...
      'Units','pixel', ...
      'Position',frmPos, ...
      'BackgroundColor',frmColor);
   
   varSpacing=(top-bottom-5*btnHt)/4;
   %------------------------------------
   % The VARIABLE label field
   n=1;
   labelStr='Current Variable';
   pos=[left top-btnHt*n-varSpacing*(n-1) 2*btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE NAME text field
   n=2;
   name='varname';
   labelStr='Name';
   pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE NAME display field
   pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'Units','pixel', ...
      'Position',pos, ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',popupColor, ...
      'String',' ', ...
      'Tag',name);
   
   %------------------------------------
   % The VARIABLE TYPE text field
   n=3;
   labelStr='Type';
   pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE TYPE display field
   labelStr=' input| output';
   name='vartype';
   pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',popupColor, ...
      'Units','pixel', ...
      'Position',pos, ...
      'Tag',name, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE RANGE text field
   n=4;
   labelStr='Range';
   pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE RANGE edit field
   name='varrange';
   callbackStr='mfedit #varrange';
   pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','edit', ...
      'Units','pixel', ...
      'Position',pos, ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',editColor, ...
      'Callback',callbackStr, ...
      'Tag',name);
   
   %------------------------------------
   % The VARIABLE DISPLAY RANGE text field
   n=5;
   labelStr='Display Range';
   pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The VARIABLE DISPLAY RANGE edit field
   name='disprange';
   callbackStr='mfedit #disprange';
   pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
   hndl=uicontrol( ...
      'Style','edit', ...
      'Units','pixel', ...
      'Position',pos, ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',editColor, ...
      'Callback',callbackStr, ...
      'Tag',name);
   
   %====================================
   % The MF frame 
   bottom=border+7*spacing+2*btnHt;
   left=right+3*spacing;
   right=maxRight-border-spacing;
   frmBorder=spacing;
   frmPos=[left-frmBorder bottom-frmBorder ...
         right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
   mfFrmHndl=uicontrol( ...
      'Style','frame', ...
      'Units','pixel', ...
      'Position',frmPos, ...
      'BackgroundColor',frmColor);
   
   mfBtnWid=1.2*btnWid;
   mfHSpacing=(right-left-2*mfBtnWid);
   mfVSpacing=(top-bottom-4*btnHt)/3;
   %------------------------------------
   % The MEMBERSHIP FUNCTION text field
   n=1;
   labelStr='Current Membership Function (click on MF to select)';
   pos=[left top-btnHt*n-mfVSpacing*(n-1) right-left btnHt];
   uicontrol( ...
      'Style','text', ...
      'BackgroundColor',frmColor, ...
      'HorizontalAlignment','left', ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The MF Name text label
   n=2; m=1;
   labelStr='Name';
   pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
   hndl=uicontrol( ...
      'Style','text', ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',frmColor, ...
      'Units','pixel', ...
      'Position',pos, ...
      'String',labelStr);
   
   %------------------------------------
   % The MF NAME edit field
   m=2;
   callbackStr='mfedit #mfname';
   name='mfname';
   pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
   hndl=uicontrol( ...
      'Style','edit', ...
      'Units','pixel', ...
      'Position',pos, ...
      'HorizontalAlignment','left', ...
      'BackgroundColor',editColor, ...
      'Tag',name, ...
      'Callback',callbackStr);
   
   %------------------------------------
   % The MF TYPE text label
   n=3; m=1;
   labelStr='Type';

⌨️ 快捷键说明

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