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

📄 mfedit.m

📁 交流 模糊控制 交流 模糊控制
💻 M
📖 第 1 页 / 共 4 页
字号:
		'Style','popupmenu', ...
		'Units','pixel', ...
		'UserData',labelStr2, ...
		'Position',pos, ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',popupColor, ...
		'Callback',callbackStr, ...
		'String',labelStr1, ...
		'Tag',name);
	
	%------------------------------------
	% The MF PARAMS text label
	n=4; m=1;
	labelStr='Params';
	pos=[left top-btnHt*n-mfVSpacing*(n-1) btnWid btnHt];
	hndl=uicontrol( ...
		'Style','text', ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',frmColor, ...
		'Units','pixel', ...
		'Position',pos, ...
		'String',labelStr);
	
	%------------------------------------
	% The MF PARAMS edit field
	n=4;
	callbackStr='mfedit #mfparams';
	name='mfparams';
	pos=[left+btnWid top-btnHt*n-mfVSpacing*(n-1) right-left-btnWid btnHt];
	hndl=uicontrol( ...
		'Style','edit', ...
		'HorizontalAlignment','left', ...
		'BackgroundColor',editColor, ...
		'Units','pixel', ...
		'Position',pos, ...
		'Callback',callbackStr, ...
		'Tag',name);
	
	callbackStr='mfedit #plotmfs';
	name='numpoints';
	pos=[0.851 0.94 0.10 0.05];
	hndl=uicontrol( ...
		'Style','edit', ...
		'HorizontalAlignment','right', ...
		'BackgroundColor',editColor, ...
		'Units','normal', ...
		'Position',pos, ...
		'String', '181', ...
		'Callback',callbackStr, ...
		'Tag',name);
	pos=[0.74 0.94 0.10 0.05];
	
	hndl=uicontrol( ...
		'Style','text', ...
		'HorizontalAlignment','right', ...
		'BackgroundColor', figColor, ...
		'Units','normal', ...
		'Position',pos, ...
		'FontSize',8, ...
		'String', 'plot points:', ...
		'Tag','pointlabel');
	
	%====================================
	% The CLOSE frame 
	bottom=border+4*spacing+btnHt;
	top=bottom+btnHt;
	left=border+2*btnWid+5*spacing;
	right=maxRight-border-spacing;
	clsBtnWid=1.2*btnWid;
	clsSpacing=(right-left-3*clsBtnWid)/2;
	
	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='mfedit #help';
	helpHndl=uicontrol( ...
		'Style','push', ...
		'Position',[left bottom clsBtnWid btnHt], ...
		'BackgroundColor',btnColor, ...
		'String',labelStr, ...
		'Callback',callbackStr);
	
	%------------------------------------
	% The CLOSE button
	labelStr='Close';
	callbackStr='fisgui #close';
	closeHndl=uicontrol( ...
		'Style','push', ...
		'Position',[right-clsBtnWid bottom clsBtnWid btnHt], ...
		'BackgroundColor',btnColor, ...
		'String',labelStr, ...
		'Callback',callbackStr);
	
	%====================================
	% The STATUS frame 
	top=border+spacing+btnHt;
	bottom=border+spacing;
	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];
	hndl=uicontrol( ...
		'Style','text', ...
		'BackgroundColor',frmColor, ...
		'HorizontalAlignment','left', ...
		'Units','pixel', ...
		'Position',pos, ...
		'Tag',name, ...
		'String',labelStr);
	
	% Plot the curves of the first input variable
	if nargin<3, varIndex=1; end
	if nargin<2, varType='input'; end
	
	mfedit('#update',varType,varIndex);
    % Call selectmf to select first mf and populate mf text boxes
    localSelectmf([], [], selectColor);
	
	% Uncover the figure
	set(figNumber, ...
		'Visible','on', 'HandleVisibility','callback');
	
elseif strcmp(action,'#update'),
	%====================================
	figNumber=watchon;
	oldfis=get(figNumber,'UserData');
	fis=oldfis{1};
	% Clear the current variable plots and redisplay
	inputAxes=findobj(figNumber,'Type','axes','Tag','input');
	outputAxes=findobj(figNumber,'Type','axes','Tag','output');
	delete([inputAxes; outputAxes])
	varAxes=findobj(figNumber,'Type','axes','Tag','variables');
	axes(varAxes);
	mfedit #plotvars
    
    % Select any variables in the FIS Editor that are new or have been double clicked  
    FuzzyEdHndl = findall(0, 'Type', 'Figure', 'Name', ['Membership Function Editor: ' fis.name]);
    if ~isempty(FuzzyEdHndl)
        % [1 0.3 0.3] is the color used by the FIS Editor to highlight variables
        SelectAxHndl = findobj(FuzzyEdHndl, 'Type', 'Axes', 'XColor', [1 0.3 0.3]);
        if ~isempty(SelectAxHndl)
            varIndex = get(SelectAxHndl,'UserData');
            varName  = get(SelectAxHndl,'Tag');
            if strcmp('i',varName(1))
                varType = 'input';
            else
                varType = 'output';
            end
        else
            % The default variable is the first input
            varIndex = 1;
            varType = 'input';    
        end
    end
    
  	currVarAxes=findobj(figNumber,'Type','axes','Tag',varType,'UserData',varIndex);
	if isempty(currVarAxes),
		statmsg(figNumber,'No variables for this system');
	else
		currVarAxesChildren=get(currVarAxes,'Children');
		set(figNumber,'CurrentObject',currVarAxesChildren(1));
		mfedit #selectvar
		statmsg(figNumber,'Ready');
	end

	watchoff(figNumber)
	
elseif strcmp(action,'#keypress'),
	%====================================
	figNumber=gcf;
	removeMFHndl=findobj(figNumber,'Type','uimenu','Tag','removemf');
    key_number = get(figNumber,'CurrentCharacter');
    if ~isempty(key_number)
        if abs(key_number)==127,
            if strcmp(get(removeMFHndl,'Enable'),'on')
			mfedit #removemf
            end
        end
    end

	
elseif strcmp(action,'#selectvar'),
	%====================================
	figNumber=watchon; 
	oldfis=get(figNumber,'UserData');
	fis=oldfis{1};
	fisType=fis.type;
	newCurrVarPatch=get(figNumber,'CurrentObject');
	%   sss=get(newCurrVarPatch)
	%   newCurrVarPatch = gcbo;
	%   if isempty(newCurrVarPatch)| ~strcmp(get(newCurrVarPatch, 'Type'), 'patch')
	%     newCurrVarPatch=findobj(figNumber, 'Tag', 'input1');
	%   end
	newCurrVar=get(newCurrVarPatch,'Parent');
	varIndex=get(newCurrVar,'UserData');
	
	varType=get(newCurrVar,'Tag');
	
	% Deselect all others if necessary
	oldCurrVar=findobj(figNumber,'Type','axes','XColor',selectColor);
	if newCurrVar~=oldCurrVar,
		set(oldCurrVar,'XColor','k','YColor','k');
		set(oldCurrVar,'LineWidth',1);
	end
	
	% Now hilight the new selection
	set(newCurrVar,'XColor',selectColor,'YColor',selectColor);
	set(newCurrVar,'LineWidth',3);
	
	% Set all current variable display registers ...
	dispRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','disprange');
	customHndl=findobj(figNumber,'Type','uimenu','Tag','addcustommf');
	
	if strcmp(fisType,'sugeno') & strcmp(varType,'output'),
		% Handle sugeno case
		dispRangeStr=' ';
		set(dispRangeHndl,'String',dispRangeStr,'UserData',dispRangeStr, ...
			'Enable','off');
		set(customHndl,'Enable','off');
	else
		dispRangeStr=[' ' mat2str(eval(['fis.' varType '(' num2str(varIndex) ').range']), 4)];   
		set(dispRangeHndl,'String',dispRangeStr,'UserData',dispRangeStr, ...
			'Enable','on');
		set(customHndl,'Enable','on');
	end
	
	if strcmp(get(figNumber,'SelectionType'),'open'),
		fisgui #findgui
	end
	
	% The VARIABLE NAME text field
	name='varname';
	hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
	
	varName=eval(['fis.' varType '(' num2str(varIndex),').name']);
	set(hndl,'String',varName);
	
	% The VARIABLE TYPE text field
	name='vartype';
	hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
	set(hndl,'String',varType);
	
	% The VARIABLE RANGE text field
	name='varrange';
	hndl=findobj(figNumber,'Type','uicontrol','Tag',name);
	rangeStr=mat2str(eval(['fis.' varType '(' num2str(varIndex),').range']),4);
	labelStr=[' ' rangeStr];
	set(hndl,'String',labelStr);
	
	statmsg(figNumber,['Selected variable "' varName '"']);
	mfedit #plotmfs
    % Call localSelectmf to select first mf and populate mf text boxes
    localSelectmf([], [], selectColor);

	watchoff(figNumber)
	
	
elseif strcmp(action,'#deselectmf'),
	%====================================
	figNumber=get(0,'CurrentFigure');
	
	currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
	varType=get(currVarAxes,'Tag');
	
	mainAxes=findobj(figNumber,'Type','axes','Tag','mainaxes');
	param=get(mainAxes,'UserData');
	currMF=param.CurrMF;
	lineHndl=findobj(mainAxes,'Tag','mfline', 'UserData', currMF);
	%  for i=1:length(lineHndlList)
	%    thisparam=get(lineHndlList(i), 'UserData');
	%    if thisparam.CurrMF == currMF,
	%      lineHndl=lineHndlList(i);
	%      break;
	%    end
	%  end
	txtHndl=findobj(mainAxes,'Type','text','UserData',currMF);
	% Clear the current MF register
	param.CurrMF=-1;
	set(mainAxes,'UserData',param);
	
	if strcmp(varType,'input'),
		backgroundColor=inputColor;
	else 
		backgroundColor=outputColor;
	end
	set(lineHndl,'Color',backgroundColor);
	set(lineHndl,'LineWidth',1);
	set(lineHndl,'Color',unselectColor);
	%    set(lineHndl, 'Tag', 'line');
	set(txtHndl,'Color',unselectColor,'FontWeight','normal');
	
	% Clean up the MF fields
	hndl=findobj(figNumber,'Type','uicontrol','Tag','mfname');
	if strcmp(get(hndl,'Enable'),'on'),
		set(hndl,'String',' ','Enable','off');
		hndl=findobj(figNumber,'Tag','mftype');
		set(hndl,'Value',1,'Enable','off');
		hndl=findobj(figNumber,'Type','uicontrol','Tag','mfparams');
		set(hndl,'String',' ','Enable','off');
		hndl=findobj(figNumber,'Type','uimenu','Tag','removemf');
		set(hndl,'Enable','off');
	end
	
elseif strcmp(action,'#varrange'),
	%====================================
	figNumber=watchon; 
	oldfis=get(figNumber,'UserData');
	fis=oldfis{1};
	currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
	varIndex=get(currVarAxes,'UserData');
	varType=get(currVarAxes,'Tag');
	
	% Get the range
	oldRange=eval(['fis.' varType '(' num2str(varIndex) ').range']);
	
	varRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','varrange');
	dispRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','disprange');
	newRangeStr=get(varRangeHndl,'String');
	
	% We'll put the brackets in later; no point in dealing with the hassle
	index=[find(newRangeStr=='[') find(newRangeStr==']')];
	newRangeStr(index)=32*ones(size(index));
	newRangeStr=['[' newRangeStr ']'];
	
	% Use eval try-catch to prevent really weird stuff...
	newRange=eval(newRangeStr,mat2str(oldRange,4));
	if length(newRange)~=2,
		statmsg(figNumber,'Range vector must have exactly two elements');
		newRange=oldRange;
	end
	if diff(newRange)<=0,
		statmsg(figNumber,'Range vector must be of the form [lowLimit highLimit]');
		newRange=oldRange;
	end
	
	rangeStr=mat2str(newRange,4);
	set(varRangeHndl,'String',[' ' rangeStr]);
	
	% The next section changes the parameters of the MFs so they span the 
	% new range. This is appropriate for Mamdani systems, and for the inputs
	% of Sugeno systems, but not for the output of Sugeno systems
	if ~(strcmp(fis.type,'sugeno') & strcmp(varType,'output')),
		if ~all(newRange==oldRange),
			% Don't bother to do anything unless it's changed
			% Change all params here
			numMFs=eval(['length(fis.' varType '(' num2str(varIndex) ').mf)']);
			for count=1:numMFs,
				oldParams=eval(['fis.' varType '(' num2str(varIndex) ').mf(' num2str(count) ').params']);
				mfType=eval(['fis.' varType '(' num2str(varIndex)  ').mf(' num2str(count) ').type']);
				[newParams,errorStr]=strtchmf(oldParams,oldRange,newRange,mfType);
				eval(['fis.' varType '(' num2str(varIndex) ').mf(' num2str(count) ').params=' mat2str(newParams) ';']);
				
			end
			eval(['fis.' varType '(' num2str(varIndex) ').range=' mat2str(newRange) ';']);
			
			updtfis(figNumber,fis,[4 5]);
			pushundo(figNumber,fis);
			
			% ... and plot
			set(dispRangeHndl,'String',[' ' rangeStr]);
			mfedit #plotmfs
		end
	end
	
	watchoff(figNumber)
	
elseif strcmp(action,'#disprange'),
	%====================================
	figNumber=watchon; 
	oldRange=[];
	oldfis=get(figNumber,'UserData');
	fis=oldfis{1};
	% Find current variable
	currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
	varIndex=get(currVarAxes,'UserData');
	varType=get(currVarAxes,'Tag');
	
	varRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','varrange');
	dispRangeHndl=findobj(figNumber,'Type','uicontrol','Tag','disprange');
	% Get the old range
	oldRangeStr=get(dispRangeHndl,'UserData');
	newRangeStr=get(dispRangeHndl,'String');
	
	% We'll put the brackets in later; no point in dealing with the hassle
	index=[find(newRangeStr=='[') find(newRangeStr==']')];
	newRangeStr(index)=32*ones(size(index));
	newRangeStr=['[' newRangeStr ']'];

⌨️ 快捷键说明

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