www.gusucode.com > 模糊控制工具箱 fuzzy logic toolbox源码程序 > fuzzy/fuzzy/gfmfdlg.m

    function out=gfmfdlg(action,fis)
%GFMFDLG Create dialog for specifying membership functions.
%   GFMFDLG(action,fis) will open a dialog
%   box for genfis1 using the default MF type 'trimf'.
%   varType and varIndex indicate exactly which variable you
%   want to add membership functions to.

%   Kelly Liu 3-28-97
%   Copyright 1994-2004 The MathWorks, Inc.
%   $Revision: 1.13.2.2 $  $Date: 2004/04/10 23:15:28 $


if strcmp(action,'#init'),
    fisType=fis.type;
    labelStr='Add membership functions';
    popupLabel1='MF type';
    popupLabel2='Number of MFs';

    %===================================
    % 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');
    figPos(3:4)=[360 360];
    maxRight=figPos(3);
    maxTop=figPos(4);
    btnWid=160;
    btnHt=23;
 
    %====================================
    % The FIGURE
    figNumber=figure( ...
        'NumberTitle','off', ...
        'Color',[0.9 0.9 0.9], ...
        'Visible','off', ...
        'MenuBar','none', ...
        'Units','pixels', ...
        'Position',figPos, ...
        'Userdata', [],...
        'Tag', 'genfis1dlg',...
        'BackingStore','off', ...
        'DockControls','off');
    figPos=get(figNumber,'position');

    %====================================
    % The MAIN frame 
    frmPos=[0 0 1 1];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);
    % The UPPER frame 
    frmPos=[0.05 0.4 0.9 0.55];
    mainFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %====================================
   
    frmPos=[0.05 0.2 0.9 0.17];
    varFrmHndl=uicontrol( ...
        'Units','normal', ...
        'Style','frame', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);
    % The POPUP frame 

    frmPos=[.05 0.05 .9 0.11];
    topFrmHndl=uicontrol( ...
        'Style','frame', ...
        'Units','normal', ...
        'Position',frmPos, ...
        'BackgroundColor',frmColor);

    %------------------------------------
    % The STRING text field
    n=1;
    labelStr='INPUT';
    pos=[.1 .865 .15 .1];
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'BackgroundColor',frmColor, ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String',labelStr);

    %====================================

    %------------------------------------
    % The POPUP text field
    labelStr='Number of MFs:';
    pos=[.1 .851 .28 .06];
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor', frmColor, ...
        'String',labelStr);
    pos=[.1 .77 .35 .06];
    btnwidth=.37;
    inmfs=getfis(fis, 'inmfs');
    if inmfs==0
       mfstr='[4]';
    else
     mfstr=mat2str(inmfs);
     if length(inmfs)==1
      mfstr=['[' mfstr ']'];
     end
    end
    uicontrol( ...
        'Units','normal', ...
        'Style','edit', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'String',mfstr(2:end-1),...
        'BackGroundColor', 'white',...
        'Tag', 'mfnumber');
    pos=[.1 .43 btnwidth .32];
    textStr={'Help:',...
             'If the # of MFs is different for each input, enter these numbers separated by a space.'};
    textStr={'',...
             'To assign a different number of MFs to each input, use spaces to seperate these numbers.'};
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String',textStr);

    rightedge=.55;   
    pos=[rightedge .851 .2 .06];
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String','MF Type:');
    %------------------------------------
    % The output text field
    labelStr='OUTPUT';
    pos=[.1 .325 .17 .06];
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String',labelStr);
    pos=[.1 .25 btnwidth .06];
    uicontrol( ...
        'Units','normal', ...
        'Style','text', ...
        'HorizontalAlignment','right', ...
        'Position',pos, ...
        'BackgroundColor',frmColor, ...
        'String','MF Type:');

    %------------------------------------
    % The output mf list field
    menuTxt=str2mat(' constant',' linear');
    pos=[rightedge 0.23 btnwidth 0.11];
    if ~isempty(fis.output(1).mf) & strcmp(fis.output(1).mf(1).type, 'constant')
       value=1;
    else
       value=2;
    end
    uicontrol( ...
        'Units','normal', ...
        'Style','listbox', ...
        'String',menuTxt, ...
        'Tag','outmftype', ...
        'HorizontalAlignment','left', ...
        'Value', value, ...
        'Position',pos, ...
        'BackgroundColor',popupColor);
    menuTxt=str2mat('trimf','trapmf','gbellmf','gaussmf','gauss2mf','pimf');
    menuTxt=str2mat(menuTxt,'dsigmf','psigmf');
    pos=[rightedge 0.45 btnwidth 0.4];
    value=3;
    if ~isempty(fis.input(1).mf)
     defaultmf=fis.input(1).mf(1).type;
     for i=1:size(menuTxt, 1)
       if strcmp(defaultmf,deblank(menuTxt(i,:)))
          value=i;
          break;
       end
     end
    end
    uicontrol( ...
        'Units','normal', ...
        'Style','listbox', ...
        'String',menuTxt, ...
        'UserData',menuTxt, ...
        'Value', value,... 
        'Tag','inmftype', ...
        'HorizontalAlignment','left', ...
        'Position',pos, ...
        'BackgroundColor',popupColor);


    %------------------------------------
    % The CANCEL button
    labelStr='Cancel';
    callbackStr='gfmfdlg #cancel';
    infoHndl=uicontrol( ...
        'Style','push', ...
        'Units','normal', ...
        'Position',[.1 .07 btnwidth .07], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

    %------------------------------------
    % The OKAY button
    labelStr='OK';
    callbackStr='gfmfdlg(''#okay'');';

    closeHndl=uicontrol( ...
        'Style','push', ...
        'Unit', 'normal',...
        'Position',[rightedge .07 btnwidth .07], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

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

    % Uncover the figure
    set(figNumber, ...
        'Visible','on');
    
    uiwait(figNumber);
    out=get(figNumber, 'Userdata');
    close(figNumber);
elseif strcmp(action,'#okay'),
    mfTypeHndl=findobj(gcbf,'Tag','inmftype');
    mfNumHndl=findobj(gcbf,'Tag','mfnumber');
    mfTypeVal=get(mfTypeHndl,'Value');
    mfTypeList=get(mfTypeHndl,'UserData');
    mfType=deblank(mfTypeList(mfTypeVal,:));
    inmfType=fliplr(deblank(fliplr(mfType)));
    mfNum=get(mfNumHndl,'String');
    outmfTypeHndl=findobj(gcbf,'Tag','outmftype');
    mfTypeVal=get(outmfTypeHndl,'Value');
    if mfTypeVal==1
     outmfType='constant';
    else
     outmfType='linear';
    end
    mfnumber=str2mat(mfNum);
    set(gcbf,'user', {mfnumber, inmfType, outmfType});
    uiresume
elseif strcmp(action,'#cancel'),
    set(gcbf, 'Userdata', []);
    uiresume
end