?? anfisedit.m
字號(hào):
end
switch thisstr
case 'Grid partition'
set(genHndl, 'String', 'Generate FIS ...');
case 'Sub. clustering'
set(genHndl, 'String', 'Generate FIS ...');
otherwise
set(genHndl, 'String', 'Load ...');
end
case '#radiotest'
curHndl=gco;
set(curHndl, 'Value', get(curHndl, 'max'));
radioHndl=findobj(gcbf, 'Tag', 'test');
for i=1:length(radioHndl)
if radioHndl(i)~=curHndl
set(radioHndl(i), 'Value', 0);
end
end
case '#help'
figNumber=watchon;
helpwin(mfilename)
watchoff(figNumber)
end; % if strcmp(action, ...
% End of function anfisedit
%==================================================
function LocalEnableBtns(fis)
% control the enable property for buttons, based on whether training data/mf/rule
% has already set
figNumber = gcbf;
startHndl = findobj(figNumber, 'Tag', 'startbtn');
if ~isfield(fis, 'trndata')| isempty(fis.trndata)| isempty(fis.input(1).mf)
%| isempty(fis.input(1).mf)|...
% ~isfield(fis, 'rule') | isempty(fis.rule)
set(startHndl, 'Enable', 'off');
else
set(startHndl, 'Enable', 'on');
end
%genHndl = findobj(gcf, 'Tag', 'genfis');
%if ~isfield(fis, 'trndata')| isempty(fis.trndata(1))
% set(genHndl, 'Enable', 'off');
%else
% set(genHndl, 'Enable', 'on');
%end
plotHndl = findobj(figNumber, 'Tag', 'plotstrc');
testHndl = findobj(figNumber, 'Tag', 'testbtn');
if isfield(fis,'input') & (isempty(fis.input(1).mf) | ~isfield(fis, 'rule') | isempty(fis.rule))
set(plotHndl, 'Enable', 'off');
set(testHndl, 'Enable', 'off');
else
set(plotHndl, 'Enable', 'on');
set(testHndl, 'Enable', 'on');
end
%==================================================
function uiHandle=LocalBuildUi(uiPos, uiStyle, uiCallback, promptStr, uiTag)
% build uicontrol
uiHandle=uicontrol( ...
'Style',uiStyle, ...
'HorizontalAlignment','left', ...
'BackgroundColor',[.75 .75 .75], ...
'Units','normalized', ...
'Max',20, ...
'Position',uiPos, ...
'Callback',uiCallback, ...
'Tag', uiTag, ...
'String',promptStr);
%==================================================
function frmHandle=LocalBuildFrmTxt(frmPos, txtStr, uiStyle, txtTag)
% Build frame and label with an edge
%frmColor=192/255*[1 1 1];
frmColor=[.75 .75 .75];
frmHandle=uicontrol( ...
'Style', uiStyle, ...
'Units','normalized', ...
'Position',frmPos, ...
'HorizontalAlignment', 'left',...
'BackgroundColor',frmColor, ...
'String', txtStr, ...
'Tag', txtTag);
% 'ForegroundColor',[1 1 1], ... %generates an edge
%==================================================
function btHandle=LocalBuildBtns(thisstyle, btnNumber, labelStr, callbackStr, uiTag)
% build buttons or check boxes so they easily aline on the right
labelColor=[0.75 0.75 0.75];
top=0.953;
left=0.825;
btnWid=0.15;
btnHt=0.05;
bottom=0.032;
% Spacing between the button and the next command's label
spacing=0.03;
yPos=top-(btnNumber-1)*(btnHt+spacing);
if strcmp(labelStr, 'Close')==1
yPos= bottom;
elseif strcmp(labelStr, 'Info')==1
yPos= bottom+btnHt+spacing;
else
yPos=top-(btnNumber-1)*(btnHt+spacing)-btnHt;
end
% Generic button information
btnPos=[left yPos btnWid btnHt];
btHandle=uicontrol( ...
'Style',thisstyle, ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Tag', uiTag, ...
'Callback',callbackStr);
%==================================================
function LocalStructureBtnCallback(eventSrc, eventdata)
% Plots initial anfis structure, can only be called when Structure button is enabled,
% therefore no need to check for existing figure. eventSrc is Structure btn hndl
% Get the default figure position at the root level
default_pos = get(0,'DefaultFigurePosition');
% The main figure is the parent of the Structure button which issued this callback
MainFigHndl = get(eventSrc,'Parent');
SubFigHndl=figure('Name', 'Anfis Model Structure',...
'Position', default_pos + [40 -40 0 0], ...
'Unit', 'normal',...
'NumberTitle','off',...
'HandleVisibility','callback',...
'Color', [.75 .75 .75],...
'MenuBar','none', ...
'DefaultTextFontSize',8+2*isunix, ...
'DeleteFcn',{@LocalCloseSubFigCallback eventSrc}, ...
'DockControls', 'off');
% Create the axis where the structure will be drawn
AxesHndl = axes('Parent',SubFigHndl,'Visible','off', ...
'Position', [0.01 0.132 0.975 0.82], ...
'XLimMode', 'Manual', ...
'Xlim', [-0.30 1.22], 'Ylim', [0 1.0]);
% Create status bar and Help/Close frames
uicontrol('Parent',SubFigHndl,'Style', 'frame',...
'Unit', 'normal',...
'BackgroundColor',[0.75 0.75 0.75], ...
'Position', [.01 .0218 .45 .073]);
uicontrol('Parent',SubFigHndl,'Style', 'frame',...
'Unit', 'normal',...
'BackgroundColor',[0.75 0.75 0.75], ...
'Position', [.47 .0218 .52 .073]);
uicontrol('Parent',SubFigHndl,'Style', 'text',...
'Unit', 'normal',...
'Position', [.02 .025 .4 .05],...
'BackgroundColor',[0.75 0.75 0.75], ...
'FontSize',get(SubFigHndl,'DefaultTextFontSize'), ...
'HorizontalAlignment','Left', ...
'String', 'Click on each node to see detailed information');
% Create Help and Close buttons
helpHndl=LocalBuildBtns('pushbutton', 0, 'Close', 'anfisedit #help', 'help');
pos=get(helpHndl, 'Position');
pos(1)=pos(1)-.17;
set(helpHndl, 'Position', pos, 'String', 'Help');
uicontrol('Parent',SubFigHndl,'Style', 'pushbutton',...
'Unit', 'normal',...
'Position', [0.825 0.032 0.15 0.05],...
'Callback', 'close(gcbf)', 'String', 'Close');
% Create the update button
UpDateBtnHndl = uicontrol('Parent',SubFigHndl,'Style', 'pushbutton',...
'Unit', 'normal',...
'Position', [0.825-2*0.17 0.032 0.15 0.05],...
'String', 'Update', ...
'CallBack',{@LocalUpDateStructure MainFigHndl AxesHndl});
% Create a listener to close the Structure GUI when the main figure is closed
listener = handle.listener(MainFigHndl, 'ObjectBeingDestroyed', ...
{@LocalCloseMainFigCallback SubFigHndl});
% Store the listener
set(SubFigHndl, 'UserData', listener);
% Disable the main figure Structure button
set(eventSrc,'Enable','off');
% Call the Local function to draw the structure on the axis
LocalUpDateStructure(UpDateBtnHndl, [], MainFigHndl, AxesHndl);
%==================================================
function LocalUpDateStructure(eventSrc, eventData, MainFigHndl, AxesHndl)
% Redraw the anfis structure on the figure when the update button is pressed
% If the Structure has already been drawn delete it and redraw
kids = get(AxesHndl,'Children');
delete(kids(ishandle(kids)));
SubFigHndl = get(eventSrc,'Parent');
% The FIS is stored in the UserData of the main figure
fis=get(MainFigHndl, 'UserData');
fis=fis{1};
% Create a text box to show node information during mouse button down on object
TextHndl=uicontrol('Parent',SubFigHndl,'Style', 'text', 'Unit', 'norm',...
'Visible', 'off',...
'Fontsize',8 + 2*isunix, ...
'BackGroundColor',[1 1 .6]);
% Give a text label to each node
text([-0.25 -0.029 0.43 0.63 1.06], [1.01 1.01 1.01 1.01 1.01], ...
{'input', 'inputmf', 'rule', 'outputmf', 'output'}, ...
'Parent',AxesHndl,'Fontsize',get(SubFigHndl,'DefaultTextFontSize'));
%======== calculate input nodes and input mfs
% The input node centres are first calculated then plotted later to ensure correct layering
instep=1/(length(fis.input)+1);
outstep=1/(length(fis.output)+1);
theta=0:pi/5:2*pi;
r= 0.02;
rsin=r*sin(theta);
rcos=r*cos(theta);
numin = length(fis.input);
total_nummf = 0;
for id = 1:numin
nummf(id) = length(fis.input(id).mf);
total_nummf = total_nummf + nummf(id);
end
mfstep = 1/(total_nummf + numin);
for id = 1:numin
total_mf_block = 0;
for jid = numin:-1:id + 1
mf_block(jid) = (nummf(jid) + 1)*mfstep;
total_mf_block = total_mf_block + mf_block(jid);
end
% Calculate the input node centres
input_node_ctr(id) = total_mf_block + (nummf(id) + 1)*mfstep/2;
for kid = 1:nummf(id)
% Calculate the input mf node centres
inputmf_node_ctr(id,kid) = total_mf_block + mfstep*(nummf(id)+1-kid);
end
end
%=========rules and output mfs
rulestep=length(fis.rule)+1;
% Plot the connections from output mf nodes to the weighted sum output nodes
for i=1:length(fis.output)
for j=1:length(fis.rule)
line([0.7 0.9], [(rulestep-j)/rulestep outstep*i], [-1 -1], 'color', 'black','Parent',AxesHndl);
end
end
% Plot the connections from the input mf nodes to the rule nodes
for id = 1:length(fis.rule)
conn = fis.rule(id).connection;
numa = length(fis.rule(id).antecedent);
y_pos_rule = (rulestep-id)/rulestep;
for jid = 1:numa
ruleindex=fis.rule(id).antecedent(jid);
if ruleindex~=0
if ruleindex < 0
thiscolor = 'green';
InfoTxt = 'Not True';
else
thiscolor = 'black';
InfoTxt = 'True';
end
mfstep=instep/(nummf(jid)+1);
% Plot the connections between the inputmf nodes and the rule nodes
LineHndl = line([0.0 0.45], ...
[inputmf_node_ctr(jid,abs(ruleindex)) y_pos_rule], [-1 -1], ...
'Color', char(thiscolor),'Parent',AxesHndl, ...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt});
end
end
% Plot the connections from the rule nodes to the output mf nodes
line([0.45 0.7], [y_pos_rule y_pos_rule], [-1 -1], 'color', 'black','Parent',AxesHndl);
% Draw the rule nodes
xcircle=r*sin(theta)+0.45;
ycircle=r*cos(theta)+y_pos_rule;
zcircle = ones(length(ycircle));
% rulecolor = AND OR
rulecolor={'blue', 'red'};
thiscolor = rulecolor{conn};
InfoTxt = ['Rule ' sprintf('%i',id)];
patch(xcircle, ycircle, 'w',...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt},...
'FaceColor',thiscolor, ...
'Parent',AxesHndl);
% Draw the outputmf nodes
xcircle=xcircle+0.25;
InfoTxt = ['Output MF ' sprintf('%i',fis.rule(id).consequent(1))];
patch(xcircle, ycircle, 'w',...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt},...
'Parent',AxesHndl);
end
% Plot the input mf nodes
for id = 1:numin
for kid = 1:nummf(id)
xcircle = rsin - 0.0;
ycircle = rcos + inputmf_node_ctr(id,kid);
zcircle = 10*ones(length(ycircle));
% Plot the connections between the inputmf nodes and the rule nodes
line([-0.2 0.0], [input_node_ctr(id) inputmf_node_ctr(id,kid)], [-1 -1], 'Parent',AxesHndl,'color', 'black');
InfoTxt = ['Input ' sprintf('%i',id) ',' ' MF ' fis.input(id).mf(kid).name];
patch(xcircle, ycircle, zcircle, 'w',...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt},...
'Parent',AxesHndl);
end
% Plot the input nodes
xcircle = rsin - 0.2;
ycircle = rcos + input_node_ctr(id);
InfoTxt = ['Input ' sprintf('%i',id)];
patch(xcircle, ycircle, 'black', ...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt}, ...
'Parent',AxesHndl);
end
%=====output nodes
line([0.9 1.1], [outstep outstep], 'color', 'black','Parent',AxesHndl);
for id=1:length(fis.output)
xcircle=rsin+0.9;
ycircle=rcos+outstep*id;
InfoTxt = ['Aggregated Output ' sprintf('%i',id)];
patch(xcircle, ycircle, zcircle, 'w',...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt},...
'Parent',AxesHndl);
end
%=======normalize and dividing node
xcircle=rsin+1.1;
ycircle=rcos+outstep;
InfoTxt = ['Output'];
patch(xcircle, ycircle, 'black',...
'ButtonDownFcn', {@LocalMouseBtnDown TextHndl InfoTxt},...
'Parent',AxesHndl);
%============== create a custom legend ===============
line([0.90 1.22 1.22 0.90 0.90],[0.0 0.0 0.2 0.2 0.0], 'Parent',AxesHndl,'Color','black');
text([0.94 1.12 1.12 1.12], [0.16 0.115 0.07 0.025], ...
{'Logical Operations', 'and', 'or', 'not'}, ...
'Fontsize',get(SubFigHndl,'DefaultTextFontSize'),'Parent',AxesHndl);
% Create the blue AND circle, the red OR circle and the green NOT line
xcircle=r*sin(theta)+1.; ycircle=r*cos(theta)+0.12; patch(xcircle, ycircle,'blue','Parent',AxesHndl);
xcircle=r*sin(theta)+1.; ycircle=r*cos(theta)+0.07; patch(xcircle, ycircle,'red','Parent',AxesHndl);
line([0.95 1.05],[0.03 0.03],'LineWidth',1,'Color','green','Parent',AxesHndl);
%==================================================
function LocalCloseMainFigCallback(eventSrc, eventData, SubFigHndl)
% A listener callback when the main figure window is closed
delete(SubFigHndl);
%==================================================
function LocalCloseSubFigCallback(eventSrc, eventData, StrctBtnHndl)
% Operates when the Structure diagram sub-figure is closed
set(StrctBtnHndl,'Enable','on');
%==================================================
function LocalMouseBtnDown(eventSrc, eventData, TextHndl, InfoTxt)
% Operates when user button downs on objects in the Anfis Model Structure window.
% eventSrc is the hndl of the object where the btn down event occurred
AxesHndl = get(eventSrc,'Parent');
FigHndl = get(AxesHndl,'Parent');
CP = get(FigHndl,'CurrentPoint');
switch get(eventSrc,'Type');
case 'line'
set(eventSrc,'LineWidth',4);
case 'patch'
set(TextHndl, ...
'String', InfoTxt, ...
'Visible', 'on');
ex = get(TextHndl,'Extent');
set(TextHndl,'Position',[CP(1,1) CP(1,2) ex(3) ex(4)]);
end
% Reset the sub-figure window btn up function, and pass the text hndl and the selected object hndl
set(FigHndl,'WindowButtonUpFcn',{@LocalWindowBtnUpFcn TextHndl eventSrc});
%==================================================
function LocalWindowBtnUpFcn(eventSrc, eventData, varargin)
% Operates when the Window Button Up occurs, varargin = [ TextHndl objHndl ]
switch get(varargin{2},'Type');
case 'line'
set(varargin{2},'LineWidth',0.5);
case 'patch'
set(varargin{1},'Visible','off');
end
% Reset the sub-figure window btn up function to do nothing
set(eventSrc,'WindowButtonUpFcn', ' ');
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -