📄 mfedit.m
字号:
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( ...
'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);
% 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
% The default initial variable is the first input
% Select it and hilight it
if nargin<3, varIndex=1; end
if nargin<2, varType='input'; 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');
if abs(get(figNumber,'CurrentCharacter'))==127,
if strcmp(get(removeMFHndl,'Enable'),'on'),
mfedit #removemf
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
watchoff(figNumber)
elseif strcmp(action,'#selectmf'),
%====================================
figNumber=watchon;
oldfis=get(figNumber,'UserData');
fis=oldfis{1};
% objHndl=get(figNumber,'CurrentObject');
objHndl = gcbo;
mainAxes=get(objHndl,'Parent');
% Find the new current MF
% oldCurrMF=get(mainAxes,'UserData');
param=get(mainAxes,'UserData');
oldCurrMF=param.CurrMF;
newCurrMF=get(objHndl,'UserData');
% Deselect other currently selected MF curves
if oldCurrMF~=newCurrMF,
if oldCurrMF~=-1
mfedit #deselectmf
end
param.CurrMF=newCurrMF;
set(mainAxes,'UserData',param);
% Determine the variable type and index
fisType=fis.type;
% Is the current variable input or output?
currVarAxes=findobj(figNumber,'Type','axes','XColor',selectColor);
varIndex=get(currVarAxes,'UserData');
varType=get(currVarAxes,'Tag');
% Find the info for the new MF
mfType=localgetmfparam(fis, varType, varIndex, newCurrMF, 'type');
mfName=localgetmfparam(fis, varType, varIndex, newCurrMF, 'name');
mfParams=localgetmfparam(fis, varType, varIndex, newCurrMF, 'params');
% Set the MF name, type and params to the right value
mfNameHndl=findobj(figNumber,'Type','uicontrol','Tag','mfname');
set(mfNameHndl,'String',[' ' mfName],'Enable','on');
mfTypeHndl=findobj(figNumber,'Type','uicontrol','Tag','mftype');
mfTypeList=get(mfTypeHndl,'String');
if strcmp(fisType,'sugeno') & strcmp(varType,'output'),
% Prepare sugeno mf type popup menu
if size(mfTypeList,1)>2,
set(mfTypeHndl,'String',get(mfTypeHndl,'UserData'));
set(mfTypeHndl,'UserData',mfTypeList);
end
else
% Prepare mamdani mf type popup menu
if size(mfTypeList,1)==2,
set(mfTypeHndl,'String',get(mfTypeHndl,'UserData'));
set(mfTypeHndl,'UserData',mfTypeList);
end
% Make the selected line bold
currLineHndl=findobj(mainAxes,'Tag','mfline','UserData',newCurrMF);
set(currLineHndl,'Color',selectColor);
mfdrag('mf', currLineHndl, mfType, mfParams);
set(currLineHndl,'LineWidth',2);
end
% Make the selected text bold
currTxtHndl=findobj(mainAxes,'Type','text','UserData',newCurrMF);
set(currTxtHndl,'Color',selectColor,'FontWeight','bold');
mfTypeList=get(mfTypeHndl,'String');
mfTypeValue=findrow(mfType,mfTypeList);
if isempty(mfTypeValue),
mfTypeList=str2mat(mfTypeList, [' ' mfType]);
mfTypeValue=findrow(mfType,mfTypeList);
set(mfTypeHndl,'String',mfTypeList,'Value',mfTypeValue);
msgStr=['Installing custom membership function "' mfType '"'];
statmsg(figNumber,msgStr);
end
set(mfTypeHndl,'Value',mfTypeValue,'Enable','on');
curr_info = get(gca, 'CurrentPoint');
hndl=findobj(figNumber, 'Tag','mfparams');
set(hndl,'String',[' ' mat2str(mfParams,4)],'Enable','on', ...
'Userdata', [curr_info(1,1) mfParams]);
hndl=findobj(figNumber,'Type','uimenu','Tag','removemf');
set(hndl,'Enable','on');
end
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -