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

📄 mfedit.m

📁 交流 模糊控制 交流 模糊控制
💻 M
📖 第 1 页 / 共 4 页
字号:
function mfedit(action,varType,varIndex);
%MFEDIT Membership function editor.
%
%   mfedit('a') generates a membership function editor that allows
%   you to modify all the membership sunctions for your FIS stored
%   in the file a.fis.
%
%   mfedit(a) operates on a MATLAB workspace variable for a FIS 
%   structure a.
%
%   mfedit alone opens the membership function editor with no FIS
%   loaded.
%   
%   The Membership Function (MF) Editor is used to create, 
%   remove, and modify the MFs for a given fuzzy system. On 
%   the left side of the diagram is a "variable palette" 
%   region that you use to select the current variable by 
%   clicking once on one of the displayed boxes. Information   
%   about the current variable is displayed in the text region 
%   below the palette area.
%
%   To the right is a plot of all the MFs for the current 
%   variable. You can select any of these by clicking once on 
%   the line or name of the MF. Once selected, you can modify 
%   the properties of the MF using the controls in the lower right.  
%   MFs are added and removed using the Edit menu.    
%
%   See also FUZZY, RULEEDIT, RULEVIEW, SURFVIEW, ANFISEDIT

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


if get(0,'ScreenDepth')>2,
   figColor=[0.9 0.9 0.9];
   selectColor=[1 0 0];
   unselectColor=[0 0 0];
   inputColor=[1 1 0.8];
   outputColor=[0.8 1 1];
else
   figColor=[1 1 1];
   selectColor=[0 0 0.1];
   unselectColor=[0 0 0.1];
   inputColor=[1 1 1];
   outputColor=[1 1 1];
end

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'),
	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
	
	% Protect against bad Sugeno FIS (with output MF params=[])
	if strcmpi(fisType,'sugeno')
		for ctOut=1:numOutputs
			for ctMF=1:length(fis.output(ctOut).mf)
				isLinear = strcmpi(fis.output(ctOut).mf(ctMF).type,'linear');
				if isempty(fis.output(ctOut).mf(ctMF).params)
					fis.output(ctOut).mf(ctMF).params = zeros(1,1+numInputs*isLinear);
				end
			end
		end
	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=100;
	btnHt=22;
	
	%====================================
	% The FIGURE
	thisfis{1}=fis;
	figNumber=figure( ...
		'Name',['Membership Function Editor: ' fisName], ...
		'NumberTitle','off', ...
        'IntegerHandle','off',...
		'Visible','off', ...
		'Color',figColor, ...
        'CloseRequestFcn','fisgui #close',...
		'MenuBar','none', ...
		'UserData',thisfis, ...
		'Position',figPos, ...
		'KeyPressFcn','mfedit #keypress', ...
		'DefaultAxesFontSize',8, ...
		'Tag','mfedit', ...
		'DoubleBuffer', 'on', ...
		'BackingStore','off');
	figPos=get(figNumber,'position');
	
	%====================================
	% The MENUBAR items
	% Call fisgui to create the menubar items
	fisgui #initialize
	
	%====================================
	% The MAIN frame 
	top=(maxTop)*0.47;
	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];
	
	%====================================
	% The MAIN axes
	tickColor=[0.5 0.5 0.5];
	axBorder=40;
	axPos=[left+axBorder+(right-left)/5 top+axBorder ...
			4/5*(right-left)-1.5*axBorder maxTop-top-border-1.5*axBorder];
	btnDownFcn='mfedit #deselectmf';
	param.CurrMF=-1;
	param.Action='';
	mainAxHndl=axes( ...
		'Units','pixel', ...
		'XColor',tickColor,'YColor',tickColor, ...
		'Color',inputColor, ...
		'Position',axPos, ...
		'Tag','mainaxes', ...
		'Userdata', param, ...
		'ButtonDownFcn',btnDownFcn, ...
		'Box','on');
	titleStr='Membership function plots';
	title(titleStr,'Color','black');
	
	%====================================
	% The VARIABLE PALETTE axes
	axBorder=5;
	axPos=[left+axBorder top+2*axBorder ...
			1/5*(right-left)-1.5*axBorder maxTop-top-border-7*axBorder];
	axHndl=axes( ...
		'Units','pixel', ...
		'Visible','off', ...
		'XColor',tickColor,'YColor',tickColor, ...
		'Position',axPos, ...
		'Tag','variables', ...
		'Box','on');
	axes(mainAxHndl)
	%draw frame
	mainFrmHndl=uicontrol( ...
		'Style','frame', ...
		'Units','pixel', ...
		'Position',frmPos, ...
		'BackgroundColor',frmColor);
	%====================================
	% The VARIABLE frame 
	top=top-spacing;
	bottom=border+4*spacing+btnHt;
	left=border+spacing;
	right=left+2*btnWid+spacing;
	frmBorder=spacing;
	frmPos=[left-frmBorder bottom-frmBorder ...
			right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
	varFrmHndl=uicontrol( ...
		'Style','frame', ...
		'Units','pixel', ...
		'Position',frmPos, ...
		'BackgroundColor',frmColor);
	
	varSpacing=(top-bottom-5*btnHt)/4;
	%------------------------------------
	% The VARIABLE label field
	n=1;
	labelStr='Current Variable';
	pos=[left top-btnHt*n-varSpacing*(n-1) 2*btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE NAME text field
	n=2;
	name='varname';
	labelStr='Name';
	pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE NAME display field
	pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'Units','pixel', ...
		'Position',pos, ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',popupColor, ...
		'String',' ', ...
		'Tag',name);
	
	%------------------------------------
	% The VARIABLE TYPE text field
	n=3;
	labelStr='Type';
	pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE TYPE display field
	labelStr=' input| output';
	name='vartype';
	pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',popupColor, ...
		'Units','pixel', ...
		'Position',pos, ...
		'Tag',name, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE RANGE text field
	n=4;
	labelStr='Range';
	pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE RANGE edit field
	name='varrange';
	callbackStr='mfedit #varrange';
	pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','edit', ...
		'Units','pixel', ...
		'Position',pos, ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',editColor, ...
		'Callback',callbackStr, ...
		'Tag',name);
	
	%------------------------------------
	% The VARIABLE DISPLAY RANGE text field
	n=5;
	labelStr='Display Range';
	pos=[left top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The VARIABLE DISPLAY RANGE edit field
	name='disprange';
	callbackStr='mfedit #disprange';
	pos=[right-btnWid top-btnHt*n-varSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','edit', ...
		'Units','pixel', ...
		'Position',pos, ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',editColor, ...
		'Callback',callbackStr, ...
		'Tag',name);
	
	%====================================
	% The MF frame 
	bottom=border+7*spacing+2*btnHt;
	left=right+3*spacing;
	right=maxRight-border-spacing;
	frmBorder=spacing;
	frmPos=[left-frmBorder bottom-frmBorder ...
			right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
	mfFrmHndl=uicontrol( ...
		'Style','frame', ...
		'Units','pixel', ...
		'Position',frmPos, ...
		'BackgroundColor',frmColor);
	
	mfBtnWid=1.2*btnWid;
	mfHSpacing=(right-left-2*mfBtnWid);
	mfVSpacing=(top-bottom-4*btnHt)/3;
	%------------------------------------
	% The MEMBERSHIP FUNCTION text field
	n=1;
	labelStr='Current Membership Function (click on MF to select)';
	pos=[left top-btnHt*n-mfVSpacing*(n-1) right-left btnHt];
	uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The MF Name text label
	n=2; m=1;
	labelStr='Name';
	pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',frmColor, ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The MF NAME edit field
	m=2;
	callbackStr='mfedit #mfname';
    labelStr = 'test';
	name='mfname';
	pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
	hndl=uicontrol( ...
		'Style','edit', ...
		'Units','pixel', ...
		'Position',pos, ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',editColor, ...
		'Tag',name, ...
		'Callback',callbackStr, ...
		'String','testval');
	
	%------------------------------------
	% The MF TYPE text label
	n=3; m=1;
	labelStr='Type';
	pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',frmColor, ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The MF TYPE popup menu
	m=2;
	callbackStr='mfedit #mftype';
	labelStr1=str2mat(' trimf',' trapmf',' gbellmf',' gaussmf',' gauss2mf',' sigmf');
	labelStr1=str2mat(labelStr1,' dsigmf',' psigmf',' pimf',' smf',' zmf');
	labelStr2=str2mat(' constant',' linear');
	name='mftype';
	pos=[left+(m-1)*(mfBtnWid+mfHSpacing) top-btnHt*n-mfVSpacing*(n-1) mfBtnWid btnHt];
	hndl=uicontrol( ...

⌨️ 快捷键说明

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