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

📄 fuzzy.m

📁 对模糊变量进行随机化
💻 M
📖 第 1 页 / 共 3 页
字号:
    name='impMethod';
    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);
    if strcmp(fisType,'sugeno'),
        set(hndl,'Enable','off');
    end

    %------------------------------------
    % The AGGREGATION METHOD text field
    n=4;
    labelStr='Aggregation';
    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 AGGREGATION METHOD popup menu
    labelStr=str2mat(' max',' sum',' probor',' Custom...');
    name='aggMethod';
    callbackStr='fuzzy #methodchange';
    pos=[right-btnWid top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','popupmenu', ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'BackgroundColor',popupColor, ...
        'Callback',callbackStr, ...
        'Tag',name, ...
        'String',labelStr);
    if strcmp(fisType,'sugeno'),
        set(hndl,'Enable','off');
    end

    %------------------------------------
    % The DEFUZZIFICATION METHOD text field
    n=5;
    labelStr='Defuzzification';
    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 DEFUZZIFICATION METHOD popup menu
    if strcmp(fisType,'mamdani'),
        % Defuzzification methods are different depending on the FIS type
        labelStr=str2mat(' centroid',' bisector',' mom',' lom', ...
            ' som',' Custom...');
    else
        labelStr=str2mat(' wtaver',' wtsum');
    end
    name='defuzzMethod';
    callbackStr='fuzzy #methodchange';
    pos=[right-btnWid top-btnHt*n-mthSpacing*(n-1) btnWid btnHt];
    hndl=uicontrol( ...
        'Style','popupmenu', ...
        'HorizontalAlignment','left', ...
        'Units','pixel', ...
        'Position',pos, ...
        'BackgroundColor',popupColor, ...
        'Callback',callbackStr, ...
        'Tag',name, ...
        'String',labelStr);

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

    %------------------------------------
    % The HELP button
    labelStr='Help';
    callbackStr='fuzzy #help';
    helpHndl=uicontrol( ...
        'Style','push', ...
        'Position',[left bottom btnWid btnHt], ...
        'BackgroundColor',btnColor, ...
        'String',labelStr, ...
        'Callback',callbackStr);

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

    fuzzy #update
    
    % Check to see if there is a populated input/output field
    if isfield(fis,'input') & length(fis.input) >= 1
        % Call localSelectVar to select it and populate the text boxes
        localSelectVar( 'input','1', figNumber, selectColor);
    elseif isfield(fis,'output') & length(fis.output) >= 1
        localSelectVar( 'output','1', figNumber, selectColor);
    end  
    
    % Uncover the figure
    set(figNumber, ...
        'Visible','on', ...
        'HandleVisibility','callback');


elseif strcmp(action,'#update'),
    %====================================
    figNumber=watchon;
    oldfis=get(figNumber,'UserData');
    fis=oldfis{1};
    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
 
    % The FIS NAME edit window
    name='fisname';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    fisName=fis.name;
    labelStr=[' ' fisName];
    set(hndl,'String',labelStr);

    % The FIS TYPE text field
    name='fistype';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    fisType=fis.type;
    set(hndl,'String',fisType);

    % Clear all current variable display registers ...
    varTypeHndl=findobj(figNumber,'Type','uicontrol','Tag','currvartype');
    set(varTypeHndl,'String',' ');
    varNameHndl=findobj(figNumber,'Type','uicontrol','Tag','currvarname');
    set(varNameHndl,'String',' ','Enable','off');
    varRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','currvarrange');
    set(varRangeHndl,'String',' ');
    
    % The AND METHOD popup menu
    name='andMethod';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    labelStr=get(hndl,'String');
    andMethod=fis.andMethod;
    val=findrow(andMethod,labelStr);
    if isempty(val),
        labelStr=str2mat([' ' andMethod],labelStr);
        msgStr=['Installing custom And method "' andMethod '"'];
        statmsg(figNumber,msgStr);
        set(hndl,'String',labelStr,'Value',1);
    elseif val~=get(hndl,'Value'),
        set(hndl,'Value',val);
    end

    % The OR METHOD popup menu
    name='orMethod';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    labelStr=get(hndl,'String');
    orMethod=fis.orMethod;
    val=findrow(orMethod,labelStr);
    if isempty(val),
        labelStr=str2mat([' ' orMethod],labelStr);
        msgStr=['Installing custom Or method "' orMethod '"'];
        statmsg(figNumber,msgStr);
        set(hndl,'String',labelStr,'Value',1);
    elseif val~=get(hndl,'Value'),
        set(hndl,'Value',val);
    end

    if ~strcmp(fisType,'sugeno'),
        % The IMPLICATION METHOD popup menu
        name='impMethod';
        hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
        labelStr=get(hndl,'String');
        impMethod=fis.impMethod;
        val=findrow(impMethod,labelStr);
        if isempty(val),
            labelStr=str2mat([' ' impMethod],labelStr);
            msgStr=['Installing custom Implication method "' impMethod '"'];
            statmsg(figNumber,msgStr);
            set(hndl,'String',labelStr,'Value',1);
        elseif val~=get(hndl,'Value'),
            set(hndl,'Value',val);
        end

        % The AGGREGATION METHOD popup menu
        name='aggMethod';
        hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
        labelStr=get(hndl,'String');
        aggMethod=fis.aggMethod;
        val=findrow(aggMethod,labelStr);
        if isempty(val),
            labelStr=str2mat([' ' aggMethod],labelStr);
            msgStr=['Installing custom Aggregation method "' aggMethod '"'];
            statmsg(figNumber,msgStr);
            set(hndl,'String',labelStr,'Value',1);
        elseif val~=get(hndl,'Value'),
            set(hndl,'Value',val);
        end
    end

    % The DEFUZZIFICATION METHOD popup menu
    name='defuzzMethod';
    hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
    labelStr=get(hndl,'String');
    defuzzMethod=fis.defuzzMethod;
    val=findrow(defuzzMethod,labelStr);
    if isempty(val),
        labelStr=str2mat([' ' defuzzMethod],labelStr);
        msgStr=['Installing custom Defuzzification method "' defuzzMethod '"'];
        statmsg(figNumber,msgStr);
        set(hndl,'String',labelStr,'Value',1);
    elseif val~=get(hndl,'Value'),
        set(hndl,'Value',val);
    end

    % Now plot the FIS diagram
    % First delete all axes except for the main one
    axHndlList=findobj(figNumber,'Type','axes');
    mainAxHndl=findobj(figNumber,'Type','axes','Tag','mainaxes');
    axHndlList(find(axHndlList==mainAxHndl))=[];
    delete(axHndlList);
    lineHndlList=findobj(figNumber,'Type','line');
    delete(lineHndlList);
    fuzzy #plotfis

    fisName=fis.name;
    msgStr=[ 'System "' fisName '": ' num2str(NumInputs) ' inputs, ' ...
        num2str(NumOutputs) ' outputs, and ' ...
        num2str(NumRules) ' rules'];
    if NumInputs==1, msgStr=strrep(msgStr,'inputs','input'); end
    if NumOutputs==1, msgStr=strrep(msgStr,'outputs','output'); end
    if NumRules==1, msgStr=strrep(msgStr,'rules','rule'); end
    statmsg(figNumber,msgStr);

    watchoff(figNumber)
    
elseif strcmp(action,'#keypress'),
    %====================================
    figNumber=gcf;
    key_number = get(figNumber,'CurrentCharacter');
    if ~isempty(key_number)
        if abs(key_number)==127,
            if ~isempty(findobj(figNumber,'Type','axes','XColor',selectColor)),
                fuzzy #rmvar
            end
        end
    end
    

elseif strcmp(action,'#addvar'),
    figNumber=watchon;
    currMenu=gcbo;
    %currMenu = eventSrc;
    varType=get(currMenu,'Tag');
    oldfis=get(figNumber,'UserData');
    fis=oldfis{1};
    % "Add" has been selected, so add a variable
    fis=addvar(fis,varType,'',[0 1],'init');
    if strcmp(varType,'input')
        numVars=length(fis.input);
    else
        numVars=length(fis.output);
    end
    newVarName=[varType num2str(numVars)];
    eval(['fis.' varType '(numVars).name = newVarName; '])
    msgStr=['Adding the ' varType ' variable "' newVarName '"'];
    statmsg(figNumber,msgStr);
    pushundo(figNumber,fis);
    %    set(figNumber,'UserData',fis);
    
    % Now replot the FIS diagram
    % First delete all axes except for the main one
    axHndlList=findobj(figNumber,'Type','axes');
    mainAxHndl=findobj(figNumber,'Type','axes','Tag','mainaxes');
    axHndlList(find(axHndlList==mainAxHndl))=[];
    delete(axHndlList);
    lineHndlList=findobj(figNumber,'Type','line');
    delete(lineHndlList);
    fuzzy #plotfis
    
    % Clear the VARIABLE NAME, TYPE, and RANGE fields
    hndl=findobj(figNumber,'Type','uicontrol','Tag','currvarname');
    set(hndl,'String',' ');
    hndl=findobj(figNumber,'Type','uicontrol','Tag','currvartype');
    set(hndl,'String',' ');
    hndl=findobj(figNumber,'Type','uicontrol','Tag','currvarrange');
    set(hndl,'String',' ');
    
    statmsg(figNumber,'Ready');
    
    % Call localSelectVar to select variable and populate text boxes
    localSelectVar( lower(varType), num2str(numVars), figNumber, selectColor);
    % Update all the other editors 
    updtfis(figNumber,fis,[2 3 4 5 6]);
   
    watchoff(figNumber);
    
    
elseif strcmp(action,'#rmvar'),
    figNumber=watchon;
    oldfis=get(figNumber,'UserData');
    fis=oldfis{1};
    currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
    if isempty(currVarAxes),
        statmsg(figNumber,'No variable was selected!');
        watchoff(figNumber)
        return
    end
    varIndex=get(currVarAxes,'UserData');
    tag=get(currVarAxes,'Tag');
    if strcmp(tag(1:5),'input'),
        varType='input';
    else
        varType='output';
    end
    
    % Find the corresponding name display field
    varNameHndl=findobj(figNumber,'Type','uicontrol','Tag','currvarname');
    if strcmp(varType, 'input'),
        varName=fis.input(varIndex).name;
    elseif strcmp(varType, 'output'),
        varName=fis.output(varIndex).name;
    end
    if strcmp(varType,'input'), 
        numVars=length(fis.input);
        %%%    varLabels=fis.InLabels;
    else
        numVars=length(fis.output);
        %%%    varLabels=fis.OutLabels;
    end
    
    % Remove a variable
    [fis,errorMsg]=rmvar(fis,varType,varIndex, true);
    if isempty(fis),
        % rmvar has failed for one reason or other
        statmsg(figNumber,errorMsg)
    else
        msgStr=['Removing the ' varType ' variable "' varName '"'];
        statmsg(figNumber,msgStr);
        
        pushundo(figNumber,fis);
        
        % Now replot the FIS diagram
        % First delete all axes except for the main one
        axHndlList=findobj(figNumber,'Type','axes');
        mainAxHndl=findobj(figNumber,'Type','axes','Tag','mainaxes');
        axHndlList(find(axHndlList==mainAxHndl))=[];
        delete(axHndlList);
        lineHndlList=findobj(figNumber,'Type','line');
        delete(lineHndlList);
        fuzzy #plotfis
        
        % Clear the VARIABLE NAME, TYPE, and RANGE fields
        hndl=findobj(figNumber,'Type','uicontrol','Tag','currvarname');
        set(hndl,'String',' ');
        hndl=findobj(figNumber,'Type','uicontrol','Tag','currvartype');
        set(hndl,'String',' ');
        hndl=findobj(figNumber,'Type','uicontrol','Tag','currvarrange');
        set(hndl,'String',' ');
    end
    
    % Call localSelectVar to select the variable and populate the text boxes    
    if strcmp(varType,'input')  & isfield(fis, 'input')
        if length(fis.input) == 0 & isfield(fis, 'output')
            % If no inputs left select the first output
            if length(fis.output) >= 1
                localSelectVar( 'output', '1', figNumber, selectColor);
            else
                % There is nothing left to plot so deselect remove variable from menu
                rmvarMenuHndl=findobj(figNumber,'Type','uimenu','Tag','removevar');
                set(rmvarMenuHndl,'Enable','off');
            end    
        elseif length(fis.input) == 1
            localSelectVar( 'input', '1', figNumber, selectColor);
        else
            localSelectVar( 'input',  num2str(max(varIndex-1, 1)), figNumber, selectColor);
        end
    elseif strcmp(varType,'output') & isfield(fis, 'output')
        if length(fis.output) == 0 & isfield(fis, 'input')
            % If no outputs left select the first input
            if length(fis.input) >= 1
                localSelectVar( 'input', '1', figNumber, selectColor);
            else
                % There is nothing left to plot so deselect remove variable from menu
                rmvarMenuHndl=findobj(figNumber,'Type','uimenu','Tag','removevar');
                set(rmvarMenuHndl,'Enable','off');
            end    
        elseif length(fis.output) == 1
            localSelectVar( 'output', '1', figNumber, selectColor);
        else
            localSelectVar( 'output',  num2str(max(varIndex-1, 1)), figNumber, selectColor);
        end
    end
    
    % Update all the other editors now that the new variable has been highlighted
    updtfis(figNumber,fis,[2 3 4 5 6]);
    
    watchoff(figNumber)
    

elseif strcmp(action,'#deselect'),
    %====================================
    figNumber=watchon; 
    % Deselect all variables
    oldCurrVar=findobj(figNumber,'Type','axes','XColor',selectColor);

⌨️ 快捷键说明

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