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

📄 mfedit.m

📁 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱 模糊逻辑工具箱
💻 M
📖 第 1 页 / 共 4 页
字号:
     else
      numInputs=0;
     end

      inLabels=[];
      for i=1:numInputs
         inLabels=strvcat(inLabels, fis.input(i).name);
      end
      
      varRange=[-1 1];
      for count=1:numMFs,
         mfName=eval(['fis.' varType '(' num2str(varIndex) ').mf(' num2str(count) ').name']);
         txtStr=deblank(mfName);
         if numMFs>6,
            % Use two columns
            if (count-1)<(numMFs/2),
               % This is column one
               xPos=0.25*diff(varRange)+varRange(1);
               yPos=(count-1)/(numMFs/2-1);
            else
               % This is column two
               xPos=0.75*diff(varRange)+varRange(1);
               yPos=(count-round(numMFs/2)-1)/(round(numMFs/2)-1);
            end
         else
            % Only one column is necessary
            xPos=0;
            yPos=(count)/(numMFs);
         end
         
         text(xPos,yPos,txtStr, ...
            'Color',unselectColor, ...
            'UserData',count, ...
            'EraseMode','normal', ...
            'HorizontalAlignment','center', ...
            'FontSize',8, ...
            'ButtonDownFcn','mfedit #selectmf');
      end
      set(gca,'XTick',[],'YTick',[], ...
         'XLim',[-1 1],'YLim',[-0.2 1.2], ...
         'Color',backgroundColor);
   else
      % This is either an input variable or a mamdani output
      dispRangeHndl=findobj(figNumber,'Tag','disprange');
      varRange=eval(get(dispRangeHndl,'String'));
      ptsHndl = findobj(figNumber, 'Tag', 'numpoints');
      numPts=get(ptsHndl, 'String');
      numPts=str2num(numPts);
      cla
      % Draw all the lines
      set(gca, ...
         'YTick',[0 0.5 1],'XTickMode','auto', ...
         'YLim',[-0.05 1.2], ...
         'Color',backgroundColor);
      [xAllMFs,yAllMFs]=plotmf(fis,varType,varIndex,numPts);
      for mfIndex=1:numMFs,
         x=xAllMFs(:,mfIndex);
         y=yAllMFs(:,mfIndex);
         mfName=eval(['fis.' varType '(' num2str(varIndex) ').mf(' num2str(mfIndex) ').name']);
         line(x,y, ...
            'Color',unselectColor, ...
            'LineWidth',1, ...
            'UserData',mfIndex, ...
            'EraseMode','normal', ...
            'Tag', 'mfline',...
            'ButtonDownFcn','mfedit #selectmf')
         centerIndex=find(y==max(y));
         centerIndex=round(mean(centerIndex));
         text(x(centerIndex), 1.1 ,mfName, ...
            'HorizontalAlignment','center', ...
            'Color',unselectColor, ...
            'FontSize',8, ...
            'UserData',mfIndex, ...
            'EraseMode','normal', ...
            'Tag', 'mftext',...
            'ButtonDownFcn','mfedit #selectmf')
         param=get(gca, 'Userdata');
         param.CurrMF=-1;
         set(gca,'UserData',param,'XLim',varRange);
         set(gca,'XLim',varRange);
      end
   end
   
   xlabel([varType ' variable "' varName '"'],'Color','black');
   
   % Clean up the MF fields
   hndl=findobj(figNumber,'Type','uicontrol','Tag','mfname');
   set(hndl,'String',' ','Enable','off');
   hndl=findobj(figNumber,'Type','uicontrol','Tag','mftype');
   set(hndl,'Value',1,'Enable','off');
   hndl=findobj(figNumber,'Type','uicontrol','Tag','mfparams');
   set(hndl,'String',' ','Enable','off');
   
elseif strcmp(action,'#removemf'),
   %====================================
   figNumber=watchon;
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   % Find the selected variable and MF
   currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
   varIndex=get(currVarAxes,'UserData');
   varType=get(currVarAxes,'Tag');
   mainAxes=findobj(figNumber,'Type','axes','Tag','mainaxes');
   param=get(mainAxes,'UserData');
   %  currMF=get(mainAxes,'UserData');
   currMF=param.CurrMF;
      
   lineHndl=findobj(mainAxes,'Type','line','UserData',currMF);
   
   txtHndl=findobj(mainAxes,'Type','text','UserData',currMF);
   
   [fis,errorStr]=rmmf(fis,varType,varIndex,'mf',currMF);
   if isempty(fis),
      statmsg(figNumber,errorStr);
   else
      delete(lineHndl);
      delete(txtHndl);
      updtfis(figNumber,fis,[3 4 5 6]);
      pushundo(figNumber,fis);
      mfedit #plotmfs
   end
   
   watchoff(figNumber)    
   
elseif strcmp(action,'#removeallmfs'),
   %====================================
   figNumber=watchon;
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   % Find the selected variable
   currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
   varIndex=get(currVarAxes,'UserData');
   varType=get(currVarAxes,'Tag');
   mainAxes=findobj(figNumber,'Type','axes','Tag','mainaxes');
      
   lineHndlList=findobj(mainAxes,'Tag','mfline');
   txtHndlList=findobj(mainAxes,'Type','text');
   
   deleteFlag=1;
   count=eval(['length(fis.' varType '(' num2str(varIndex) ').mf)']);
   while count>=1,
      [fis,errorStr]=rmmf(fis,varType,varIndex,'mf',count);
      count=count-1;
      if isempty(fis),
         % if any of these MFs are used in the rule base, we can't delete
         deleteFlag=0;
         statmsg(figNumber,errorStr);
         count=0;
      end
   end
   if deleteFlag
      delete(lineHndlList);
      delete(txtHndlList);
      pushundo(figNumber,fis);
      updtfis(figNumber,fis,[]);
      mfedit #plotmfs
   end
   
   watchoff(figNumber)    
   
elseif strcmp(action,'#addcustommf'),
   %====================================
   figNumber=watchon;
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   % Find the selected variable and MF
   currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
   varIndex=get(currVarAxes,'UserData');
   varType=get(currVarAxes,'Tag');
   
   cmfdlg(figNumber,fis,varType,varIndex);
   watchoff(figNumber);
   
elseif strcmp(action,'#addmfs'),
   %====================================
   figNumber=watchon;
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   % Find the selected variable and MF
   currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
   varIndex=get(currVarAxes,'UserData');
   varType=get(currVarAxes,'Tag');
   
   mfdlg(figNumber,fis,varType,varIndex);
   mfdlgfig=findobj(0, 'Tag', 'mfdlg');
   waitfor(mfdlgfig);
   watchoff(figNumber);
   oldfis=get(figNumber,'UserData');
   fis=oldfis{1};
   updtfis(figNumber,fis,[3]);
elseif strcmp(action,'#plotvars'),
   %====================================
   figNumber=gcf;
   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

   for i=1:numInputs
      numInputMFs(i)=length(fis.input(i).mf);
   end
   
   for i=1:numOutputs
      numOutputMFs(i)=length(fis.output(i).mf);
   end
   if isfield(fis, 'rule')
     numRules=length(fis.rule);
   else
     numRules=0;
   end
   fisName=fis.name;
   fisType=fis.type;
   
   mainAxHndl=gca;
   set(mainAxHndl,'Units','pixel','XTick',[],'YTick',[])
   mainAxPos=get(mainAxHndl,'Position');
   axis([mainAxPos(1) mainAxPos(1)+mainAxPos(3) ...
         mainAxPos(2) mainAxPos(2)+mainAxPos(4)]);
   xCenter=mainAxPos(1)+mainAxPos(3)/2;
   yCenter=mainAxPos(2)+mainAxPos(4)/2;
   title('FIS Variables')
   set(get(mainAxHndl,'Title'),'Visible','on','FontSize',10,'Color','black')
   
   % Inputs first
   
   if get(0,'ScreenDepth')>2,
      inputColor=[1 1 0.5];
      outputColor=[0.5 1 1];
   else
      inputColor=[1 1 1];
      outputColor=[1 1 1];
   end
   
   tickColor=[0.5 0.5 0.5];
   fontSize=8;
   
   boxWid=(1/2)*mainAxPos(3);
   boxHt=(1/(max(4,numInputs)))*mainAxPos(4);
   xInset=boxWid/10;
   yInset=boxHt/5;
   
   for varIndex=1:numInputs,
      boxLft=mainAxPos(1);
      boxBtm=mainAxPos(2)+mainAxPos(4)-boxHt*varIndex;
      axPos=[boxLft+xInset boxBtm+yInset boxWid-2*xInset boxHt-2*yInset];
      
      varName=eval(['fis.input(' num2str(varIndex) ').name']);
      axName='input';
      axHndl=axes( ...
         'Units','pixel', ...
         'Box','on', ...
         'XTick',[],'YTick',[], ...
         'XColor',tickColor,'YColor',tickColor, ...
         'YLim',[-0.1 1.1], ...
         'Color',inputColor, ...
         'Tag',axName, ...
         'UserData',varIndex, ...
         'Position',axPos);
      mfIndex=(1:numInputMFs(varIndex))+sum(numInputMFs(1:(varIndex-1)));
      colorOrder=get(gca,'ColorOrder');
      
      % Plot three cartoon membership functions in the box
      xMin=-1; xMax=1;
      x=(-1:0.1:1)';
      y1=exp(-(x+1).^2/0.32); y2=exp(-x.^2/0.32); y3=exp(-(x-1).^2/0.32);
      xlineMatrix=[x x x];
      ylineMatrix=[y1 y2 y3];
      line(xlineMatrix,ylineMatrix,'Color','black');
      xiInset=(xMax-xMin)/10;
      axis([xMin-xiInset xMax+xiInset -0.1 1.1])
      
      % Lay down a patch that simplifies clicking on the region
      patchHndl=patch([xMin xMax xMax xMin],[0 0 1 1],'black');
      set(patchHndl, ...
         'EdgeColor','none', ...
         'FaceColor','none', ...
         'ButtonDownFcn','mfedit #selectvar');
      
      % Now put on the variable name as a label
      xlabel(varName);
      labelName=[axName 'label'];
      set(get(axHndl,'XLabel'), ...
         'FontSize',fontSize, ...
         'Color','black', ...
         'Tag',labelName); 
   end
   
   % Now for the outputs
   boxHt=(1/(max(4,numOutputs)))*mainAxPos(4);
   
   for varIndex=1:numOutputs,
      boxLft=mainAxPos(1)+boxWid;
      boxBtm=mainAxPos(2)+mainAxPos(4)-boxHt*varIndex;
      axPos=[boxLft+xInset boxBtm+yInset boxWid-2*xInset boxHt-2*yInset];
      
      varName=eval(['fis.output(' num2str(varIndex) ').name']);
      axName='output';
      axHndl=axes( ...
         'Units','pixel', ...
         'Box','on', ...
         'Color',outputColor, ...
         'XTick',[],'YTick',[], ...  
      'XLim',[xMin xMax],'YLim',[-0.1 1.1], ...
         'XColor',tickColor,'YColor',tickColor, ...
         'Tag',axName, ...
         'UserData',varIndex, ...
         'Position',axPos);
      mfIndex=(1:numOutputMFs(varIndex))+sum(numOutputMFs(1:(varIndex-1)));
      if ~strcmp(fisType,'sugeno'),
         % Only try to plot outputs it if it's not a Sugeno-style system
         x=[-1 -0.5 0 0.5 1]';
         xlineMatrix=[x x x];
         ylineMatrix=[0 1 0 0 0;0 0 1 0 0; 0 0 0 1 0]';
         line(xlineMatrix,ylineMatrix,'Color','black');
         xoInset=(xMax-xMin)/10;
      else
         text(0,0.5,'f(u)', ...
            'FontSize',fontSize, ...
            'Color','black', ...
            'HorizontalAlignment','center');
      end
      
      % Lay down a patch that simplifies clicking on the region
      patchHndl=patch([xMin xMax xMax xMin],[0 0 1 1],'black');
      set(patchHndl, ...
         'EdgeColor','none', ...
         'FaceColor','none', ...
         'ButtonDownFcn','mfedit #selectvar');
      
      xlabel(varName);
      labelName=[axName 'label'];
      set(get(axHndl,'XLabel'), ...
         'FontSize',fontSize, ...
         'Color','black', ...
         'Tag',labelName);
   end
   
   hndlList=findobj(figNumber,'Units','pixels');
   set(hndlList,'Units','normalized')
   
elseif strcmp(action,'#help');
   figNumber=watchon;
   helpwin(mfilename)
   watchoff(figNumber)
   
end;    % if strcmp(action, ...

function out=localgetmfparam(fis, varType, varNum, mfNum, param)
switch varType
case 'input'
   switch param
   case 'name'
      out=fis.input(varNum).mf(mfNum).name;
   case 'type'
      out=fis.input(varNum).mf(mfNum).type;
   case 'params'
      out=fis.input(varNum).mf(mfNum).params;
   end   
case 'output'
   switch param
   case 'name'
      out=fis.output(varNum).mf(mfNum).name;
   case 'type'
      out=fis.output(varNum).mf(mfNum).type;
   case 'params'
      out=fis.output(varNum).mf(mfNum).params;
   end   
end
	 

⌨️ 快捷键说明

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