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

📄 ruleedit.m

📁 模糊控制工具箱,很好用的,有相应的说明文件,希望对大家有用!
💻 M
📖 第 1 页 / 共 3 页
字号:
function ruleedit(action);
%
%  Purpose
%  Rule editor and parser.
%  Synopsis
%  ruleedit('a')
%  ruleedit(a)
%  Description
%  
%  The Rule Editor, when invoked using ruleedit('a'), is used to modify the
%  rules of a FIS structure stored in a file, a.fis. It can also be used to
%  inspect the rules being used by a fuzzy inference system. 
%  To use this editor to create rules, you must first have all of the input
%  and output variables you want to use defined with the FIS editor. You can
%  create the rules using the listbox and check
%  box choices for input and
%  output variables, connections, and weights. 
%  The syntax ruleedit(a) is used when you want to operate on a workspace
%  variable for a FIS structure called a. 
%
%  Menu Items
%  On the Rule Editor, there is a menu bar that allows you to open related GUI 
%  tools, open and save systems, and so on. The File menu for the Rule Editor 
%  is the same as the one found on the FIS Editor. Refer to the Reference 
%  entry fuzzy for more information.
%  Use the Edit menu items:
%  Undo: to undo the most recent change.
%  Use the View menu items:
%  Edit FIS properties... to invoke the FIS Editor.
%  Edit membership functions... to invoke the Membership Function Editor.
%  View rules... to invoke the Rule Viewer.
%  View surface... to invoke the Surface Viewer.
%  Use the Options menu items:
%  Language to select the language: English, Deutsch, and Francais
%  Format: to select the format: 
%  verbose uses the words *if* and *then* and so on to create actual 
%  sentences.
%  symbolic substitutes some symbols for the words used in the verbose mode. 
%  For example, *if A and B then C* becomes *A & B => C.*
%  indexed mirrors how the rule is stored in the FIS matrix.
%
%  See also ADDRULE, MFEDIT, RULEVIEW, SHOWRULE, SURFVIEW

%   Ned Gulley, 3-30-94 Kelly Liu, 4-10-97, N. Hickey 03-17-01
%   Copyright 1994-2004 The MathWorks, Inc.
%   $Revision: 1.52.2.3 $  $Date: 2004/04/10 23:15:35 $

if nargin<1,
    newFis=newfis('Untitled');
    newFis=addvar(newFis,'input','input1',[0 1],'init');
    newFis=addvar(newFis,'output','output1',[0 1],'init');
    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;

switch action,
case '#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];
    axColor=128/255*[1 1 1];
    border=.01;
    spacing=.01;
    figPos=get(0,'DefaultFigurePosition');
    maxRight=1;
    maxTop=1;
    btnWid=.14;
    btnHt=0.05;
 
    %====================================
    % The FIGURE
    thisfis{1}=fis;
    figNumber=figure( ...
        'Name',['Rule Editor: ' fisName], ...
        'NumberTitle','off', ...
        'IntegerHandle','off',...
        'Color',frmColor, ...
        'CloseRequestFcn','fisgui #close',...
        'MenuBar','none', ...
        'Visible','off', ...
        'UserData',thisfis, ...
        'Position',figPos, ...
        'Tag','ruleedit', ...
        'BackingStore','off', ...
        'DockControls', 'off');
    figPos=get(figNumber,'position');

    %====================================
    % The MENUBAR items
    % Call fisgui to create the menubar items
    fisgui #initialize

    %========================================================
    % The MAIN frame 
    bottom=border;
    top=maxTop-border; 
    right=maxRight-border;
    left=border;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2];
    mainFrmHndl=uicontrol( ...
        'Units','normal', ...
        'Style','frame', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);
    %====================================

    bottom=border+4*spacing+btnHt;
    % The RULES frame 
    top=maxTop-border-spacing;
    right=maxRight-border-spacing;
    left=border+spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2];
    ruleFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);
    %------------------------------------
    % The RULES edit window
    rulePos=[left top-(top-bottom)*2/5-border (right-left) (top-bottom)*2/5];
    if numRules>0,
        labelStr=' ';
    else
        labelStr=' ';
        msgStr=['No rules for system "' fisName '"'];
        statmsg(figNumber,msgStr);
    end
    name='rulewindow';
    pos=[left bottom btnWid*2 btnHt];
    ruleHndl=uicontrol( ...
        'Style','listbox', ...
        'Units','normal', ...
        'Position',rulePos, ...
        'BackgroundColor',editColor, ...
        'HorizontalAlignment','left', ...
        'Callback', 'ruleedit #getrule',...
        'Max',1, ...
        'Tag',name);
    %========radio button for and, or=========
    frmPos=[left bottom ...
        btnWid+spacing btnHt*2.6];
    clsFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);
    labelPos=[left+1*spacing bottom+btnHt*2 ...
        btnWid*.9 btnHt];
    clsFrmHndl=uicontrol( ...
        'Style','text', ...
        'Units','normal', ...
        'Position',labelPos, ...
        'String', 'Connection',...
        'BackgroundColor',frmColor);
    pos=[left+2*spacing bottom+1*spacing btnWid*.6 btnHt];
    helpHndl=uicontrol( ...
        'Style','radio', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'String','and', ...
        'Tag', 'radio',...
        'Max', 1,...
        'Value', 1,...
        'Callback','ruleedit #radio');
    pos=[left+2*spacing bottom+btnHt+1*spacing btnWid*.6 btnHt];
    helpHndl=uicontrol( ...
        'Style','radio', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'String','or', ...
        'Tag', 'radio',...
        'Max', 1,...
        'Callback','ruleedit #radio');
    %=====weight text=================
    pos=[left+(btnWid)+btnHt/2+spacing bottom+btnHt*2 btnWid*.7 btnHt];
    helpHndl=uicontrol( ...
        'Style','text', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String','Weight:');
    pos=[left+btnWid+btnHt bottom btnWid/2 btnHt];
    helpHndl=uicontrol( ...
        'Style','edit', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor','white', ...
        'String',num2str(1),...
        'Callback', 'wStr=max(min(1, str2double(get(gcbo, ''String''))), 0); set(gcbo, ''string'', num2str(wStr))', ... 
        'Tag', 'weight');
    %=========delete======================
    boxDstn=btnWid+spacing;
    boxWidth=(right-left)/6;
    pos=[left+boxDstn*2 bottom btnWid btnHt];
    helpHndl=uicontrol( ...
        'Style','pushbutton', ...
        'Units','normal', ...
        'Position',pos, ...
        'String','Delete rule',...
        'Callback', 'ruleedit #delete',...
        'Tag', 'delete');
 
    %========button for add=========
    pos=[left+boxDstn*3 bottom btnWid btnHt];
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'String','Add rule', ...
        'Callback','ruleedit #add');
    %========button for apply=========
    pos=[left+boxDstn*4 bottom btnWid btnHt];
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'String','Change rule', ...
        'Callback','ruleedit #add');
    %=======buttons for shift=============
    pos=[right-2*spacing-btnWid*2/3 bottom btnWid/3 btnHt];
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'Tag', 'shiftright',...
        'String','<<', ...
        'Callback','ruleedit #shiftright');
    pos=[right-spacing-btnWid/3 bottom btnWid/3 btnHt];
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',pos, ...
        'BackgroundColor',btnColor, ...
        'Tag', 'shiftleft',...
        'String','>>', ...
        'Callback','ruleedit #shiftleft');

    %====================================
    % The CLOSE frame 
    bottom=border+4*spacing+btnHt;
    top=bottom+btnHt;
    right=maxRight-border-spacing;
    % Left should be snug up against Rule Format frame
    left=border+spacing;

    frmBorder=spacing;

    %====================================
    % The STATUS frame 
    bottom=border+spacing;
    top=bottom+btnHt;
    right=maxRight-border-spacing;
    left=border+spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        (right-left)*2/3+frmBorder*2 top-bottom+frmBorder*2];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    frmPos=[left-frmBorder+(right-left)*2/3+frmBorder*3 bottom-frmBorder ...
        (right-left)*1/3-frmBorder top-bottom+frmBorder*2];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The STATUS text window
    labelStr=['FIS Name: ' fisName];
    name='status';
    pos=[left bottom (right-left)/2 btnHt];
    txtHndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','normal', ...
        'Position',pos, ...
        'Tag',name, ...
        'String',labelStr);
    %------------------------------------
    % The HELP button
%    bottom=bottom+spacing;
    labelStr='Help';
    callbackStr='ruleedit #help';
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',[right-2*btnWid-spacing bottom btnWid btnHt], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

    %------------------------------------
    % The CLOSE button
    labelStr='Close';
    callbackStr='fisgui #close';
    closeHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',[right-btnWid bottom btnWid btnHt], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);
    ruleedit #update

    % Normalize all coordinates
    hndlList=findobj(figNumber,'Units','pixels');
    set(hndlList,'Units','normalized');

    % Uncover the figure
    thisfis{1}=fis;
    set(figNumber, ...
        'Visible','on', ...
        'UserData',thisfis, ...
        'HandleVisibility','callback');

%%init 
   index=1;
   localgetrule(figNumber, index, fis)
case '#update',
    %====================================
    
    figNumber=watchon;
    
    oldfis=get(figNumber,'UserData');
    fis=oldfis{1};
    numRules=length(fis.rule);
    fisName=fis.name;

    % The RULES FORMAT menu
    popupHndl=findobj(figNumber,'Type','uimenu','Tag','rulefrmt', 'Checked','on');
    formatStr=lower(get(popupHndl,'Label'));
    formatStr=deblank(formatStr);
    formatStr=fliplr(deblank(fliplr(formatStr)));
    % The RULES edit window
    name='rulewindow';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    if numRules>0,
        langHndl=findobj(figNumber,'Type','uimenu', 'Tag', 'lang', 'Checked','on');
        lang=lower(get(langHndl,'Label'));

⌨️ 快捷键说明

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