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

📄 fuzzy.m

📁 对模糊变量进行随机化
💻 M
📖 第 1 页 / 共 3 页
字号:
function fuzzy(action);
%FUZZY  Basic FIS editor.
%   The FIS Editor displays high-level information about a 
%   Fuzzy Inference System. At the top is a diagram of the 
%   system with each input and output clearly labeled. By 
%   double-clicking on the input or output boxes, you can bring 
%   up the Membership Function Editor. Double-clicking on the 
%   fuzzy rule box in the center of the diagram will bring up 
%   the Rule Editor.                     
%                                                
%   Just below the diagram is a text field that displays the 
%   name of the current FIS. In the lower left of the window are 
%   a series of popup menus that allow you to specify the various 
%   functions used in the fuzzy implication process. In the lower 
%   right are fields that provide information about the current 
%   variable. The current variable is determined by clicking once
%   on one of the input or output boxes.
%
%   See also MFEDIT, RULEEDIT, RULEVIEW, SURFVIEW, ANFISEDIT.

%   Ned Gulley, 4-30-94, Kelly Liu 7-10-96, N. Hickey 17-03-01
%   Copyright 1994-2002 The MathWorks, Inc. 
%   $Revision: 1.41 $  $Date: 2002/04/02 21:25:25 $

% The # symbol is used to mark all callbacks into this function
selectColor=[1 0.3 0.3];

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;

if strcmp(action,'#initialize'),
    % Detect any FIS Editors out there with exactly the same name
    fisName=fis.name;
    figName=['FIS Editor: ' fisName];
    while findall(0,'Type','figure','Name',figName),
        nameLen=length(fisName);
        lastChar=fisName(nameLen);
        if abs(lastChar)>47 & abs(lastChar)<58,
            fisName(nameLen)=lastChar+1;
        else
            fisName=[fisName '2'];
        end
        fis.name=fisName;
        figName=['FIS Editor: ' fisName];
    end

    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=110;
    btnHt=23;
 
    %====================================
    % The FIGURE
    thisfis{1}=fis;
    figNumber=figure( ...
        'Name',figName, ...
        'NumberTitle','off', ...
        'Color',[0.9 0.9 0.9], ...
        'CloseRequestFcn','fisgui #close',...
        'IntegerHandle','off',...
        'Visible','off', ...
        'MenuBar','none', ...
        'UserData',thisfis, ...
        'Units','pixels', ...
        'DefaultAxesXColor','black', ...
        'DefaultAxesYColor','black', ...
        'Position',figPos, ...
        'Tag','fuzzy', ...
        'ButtonDownFcn','fuzzy #deselect', ...
        'KeyPressFcn','fuzzy #keypress');
    figPos=get(figNumber,'position');

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

    %====================================
    % The AXES frame 
    top=maxTop-border;
    bottom=border+7*btnHt+14*spacing;
    right=maxRight-border;
    left=border;
    axBorder=spacing;
    axPos=[left-axBorder bottom-0.5*axBorder ...
        right-left+axBorder*2 top-bottom+axBorder*2];
    axHndl=axes( ...
        'Box','on', ...
        'Units','pixels', ...
        'Position',axPos, ...
        'Tag','mainaxes', ...
        'Visible','on');

    %====================================
    % The MAIN frame 
    top=border+7*btnHt+12*spacing;
    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];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %====================================
    % 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+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    topFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The STATUS text window
    labelStr=' ';
    name='status';
    pos=[left bottom right-left btnHt];
    statHndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'Tag',name, ...
        'String',labelStr);

    %====================================
    % The TOP frame 
    top=border+7*btnHt+11*spacing;
    bottom=top-btnHt;
    right=maxRight-border-spacing;
    left=border+spacing;

    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    topFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The FIS NAME text window
    labelStr='FIS Name:';
    pos=[left top-btnHt btnWid btnHt];
    hndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The FIS NAME edit window
    name='fisname';
    pos=[left+spacing+btnWid top-btnHt btnWid btnHt];
    hndl=uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'Tag',name);

    %------------------------------------
    % The FIS TYPE text window
    labelStr='FIS Type:';
    pos=[right-spacing-2*btnWid top-btnHt btnWid btnHt];
    hndl=uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'Units','pixel', ...
        'String',labelStr);

    %------------------------------------
    % The FIS TYPE text display
    labelStr=' mamdani';
    name='fistype';
    pos=[right-btnWid top-btnHt btnWid btnHt];
    hndl=uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'BackgroundColor',frmColor, ...
        'Position',pos, ...
        'Tag',name, ...
        'String',labelStr);

    %====================================
    % The VARIABLES frame 
    top=border+6*btnHt+8*spacing;
    bottom=border+7*spacing+2*btnHt;
    right=maxRight-border-spacing;
    left=(maxRight)/2+2*spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    varFrmHndl=uicontrol( ...
        'Units','pixel', ...
        'Style','frame', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    varSpacing=(top-bottom-4*btnHt)/3;
    %------------------------------------
    % The CURRENT VARIABLE text field
    n=1;
    labelStr='Current Variable';
    pos=[left top-btnHt*n-varSpacing*(n-1) right-left btnHt];
    uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The CURRENT VARIABLE NAME text field
    n=2;
    labelStr='Name';
    pos=[left top-btnHt*n-varSpacing*(n-1) right-left btnHt];
    hndl=uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The CURRENT VARIABLE NAME edit field
    callbackStr='fuzzy #varname';
    name='currvarname';
    pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
    inputVarNameHndl=uicontrol( ...
        'Units','pixel', ...
        'Style','edit', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'Enable','off', ...
        'BackgroundColor',editColor, ...
        'Tag',name, ...
        'Callback',callbackStr);

    %------------------------------------
    % The CURRENT VARIABLE TYPE text field
    n=3;
    labelStr='Type';
    pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
    uicontrol( ...
        'Units','pixel', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String',labelStr);

    %------------------------------------
    % The CURRENT VARIABLE TYPE text field
    name='currvartype';
    pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'BackgroundColor',frmColor, ...
        'Units','pixel', ...
        'Position',pos, ...
        'Tag',name);

    %------------------------------------
    % The CURRENT VARIABLE RANGE text field
    n=4;
    labelStr='Range';
    pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
    outputVarNameHndl=uicontrol( ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Units','pixel',...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String',labelStr);

    %------------------------------------
    % The CURRENT VARIABLE RANGE display field
    name='currvarrange';
    pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
    outputVarNameHndl=uicontrol( ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Units','pixel',...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'Tag',name);


    %====================================
    % The METHODS frame 
    bottom=border+4*spacing+btnHt;
    left=border+spacing;
    right=(maxRight)/2-spacing;
    frmBorder=spacing;
    frmPos=[left-frmBorder bottom-frmBorder ...
        right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
    mthFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','pixel', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    mthSpacing=(top-bottom-5*btnHt)/4;
    %------------------------------------
    % The AND METHOD text field
    n=1;
    labelStr='And method';
    pos=[left top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The AND METHOD popup menu
    labelStr=str2mat(' min',' prod',' Custom...');
    name='andMethod';
    callbackStr='fuzzy #methodchange';
    pos=[right-btnWid top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','popupmenu', ...
        'BackgroundColor',popupColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'Callback',callbackStr, ...
        'Tag',name, ...
        'String',labelStr);

    %------------------------------------
    % The OR METHOD text field
    n=2;
    labelStr='Or method';
    pos=[left top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The OR METHOD popup menu
    labelStr=str2mat(' max',' probor',' Custom...');
    name='orMethod';
    callbackStr='fuzzy #methodchange';
    pos=[right-btnWid top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','popupmenu', ...
        'HorizontalAlignment','left', ...
        'BackgroundColor',popupColor, ...
        'Units','pixel', ...
        'Position',pos, ...
        'Callback',callbackStr, ...
        'Tag',name, ...
        'String',labelStr);

    %------------------------------------
    % The IMPLICATION METHOD text field
    n=3;
    labelStr='Implication';
    pos=[left top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'String',labelStr);

    %------------------------------------
    % The IMPLICATION METHOD popup menu
    labelStr=str2mat(' min',' prod',' Custom...');

⌨️ 快捷键说明

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