📄 gui_ar1.m
字号:
function gui_ar1(action,in1,in2);
%# call t3mi t1bd t15ep t2ap s3ma s1bs s15es s2as s25hs
%# call sumop
% gui_ar1
%
% GUI driven demonstration file for approximate reasoning :
% Simple temperature control.
%
% This GUI demo replaces the files st_demo.m and st_dsub.m
% used in fuzdemo2.m.
%
% FSTB - Fuzzy Systems Toolbox for MATLAB
% Copyright (c) 1993-1996 by Olaf Wolkenhauer
% Control Systems Centre at UMIST
% Manchester M60 1QD, UK
%
% 16-October-19946
% Last change 19/11/96
% possible actions:
% 'start' initialises the demo file.
% 'redraw' following each change in menus redraw
% 'done' exit the demo
% 'set_temp' editable text box - checks data
% 'set_graphs' prepares plots
% 'reason' approximate reasoning procedure
if nargin<1,
action='start';
end;
% Declare handles of menus global :
global Inf_Hndl Acc_Hndl Temp_Hndl
% Declare variables global :
global T TEMP P POWER temp output infop accop B
% Declare axes for plots global :
global temp_axes power_axes
oldFigNumber = [];
if strcmp(action,'start'),
% Graphics initialization
figNumber = figure;
oldFigNumber = watchon;
set(gcf, ...
'NumberTitle','off', ...
'Name','Approximate Reasoning', ...
'backingstore','off',...
'Units','normalized');
% Information for all buttons
labelColor=192/255*[1 1 1];
top=0.95; bottom=0.05;
yInitLabelPos=0.90;
left = 0.78; left_label=left-0.004;
labelWid=0.18; labelHt=0.05;
btnWid = 0.18; btnHt=0.07;
% Spacing between the label and the button for the same command
btnOffset=0.003;
% Spacing between the button and the next command's label
spacing=0.05; % vertical gap
% The CONSOLE frame
frmBorder=0.02;
yPos=0.05-frmBorder;
frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
console_Hndl=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.5 0.5 0.5]);
% The INFERENCE command popup button/menu
btnNumber=1;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
% Generic label information
labelPos=[left_label yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',' Inference');
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
Inf_Hndl=uicontrol( ...
'Style','Popup',...
'String','t3mi|t2ap|t1bd',...
'Position', btnPos, ...
'Value',[ 1 ],...
'Units','normalized',...
'CallBack','gui_ar1(''redraw'')');
% The ACCUMULATION command popup button/menu
btnNumber=2;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
% Generic label information
labelPos=[left_label yLabelPos-labelHt labelWid labelHt];
uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'BackgroundColor',labelColor, ...
'HorizontalAlignment','left', ...
'String',' Accumulation');
% Generic popup button information
btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
Acc_Hndl = uicontrol( ...
'Style','popup', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',' s3ma| sumop', ...
'Value', [ 1 ], ...
'Callback','gui_ar1(''redraw'')');
% The TEMPERATURE editable text box
btnNumber=3;
yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
labelPos=[left yLabelPos-labelHt labelWid labelHt];
power_text = uicontrol( ...
'Style','text', ...
'Position', labelPos, ...
'Units','normalized', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white', ...
'Max', 2, ...
'String','Temperature');
btnPos=[left+0.02 yLabelPos-labelHt-btnHt-btnOffset ...
0.5*btnWid+frmBorder btnHt];
Temp_Hndl = uicontrol( ...
'Style','edit', ...
'Position', btnPos, ...
'Units','normalized', ...
'String',' 16',...
'CallBack','gui_ar1(''set_temp''); gui_ar1(''redraw'')');
% The INFO button
uicontrol( ...
'Style','push', ...
'Units','normalized', ...
'Position',[left bottom+(2*labelHt)+spacing btnWid 2*labelHt], ...
'String','Info', ...
'Callback','gui_ar1(''info'')');
% The CLOSE button
done_button=uicontrol('Style','Pushbutton', ...
'Position',[left bottom btnWid 2*labelHt], ...
'Units','normalized','Callback',...
'gui_ar1(''done'')','String','Close');
% Create axes for plots :
temp_axes = axes('Position',[.12 .58 .6 .3], ...
'XLim',[0 45],'YLim',[0 1]);
power_axes = axes('Position',[.12 .14 .6 .3], ...
'XLim',[0 100],'YLim',[0 1]);
% Create intial result for reasonig procedure :
TEMP=[-inf 8 23; 0 18 30; 8 23 35; 18 30 45];
POWER=[-100 -50 0; -100 -20 50; -50 20 100; 0 50 100];
[T,TEMP]=con2dis(TEMP,200);
[P,POWER]=con2dis(POWER,200);
infop = 't3mi';
accop = 's3ma';
gui_ar1('set_temp');
gui_ar1('reason');
gui_ar1('set_graphs');
watchoff(oldFigNumber);
elseif strcmp(action,'done'),
close(gcf);
clear global T TEMP P POWER temp output infop accop B
clear global Inf_Hndl Acc_Hndl Temp_Hndl
clear global temp_axes power_axes
elseif strcmp(action,'redraw'),
% recomputes outset and output value and updates display
val = get(Inf_Hndl,'Value');
if (val == 1),
infop='t3mi';
elseif (val == 2),
infop='t2ap';
elseif (val == 3),
infop='t1bd';
end;
val = get(Acc_Hndl,'Value');
if (val == 1),
accop='s3ma';
elseif (val == 2),
accop='sumop';
end;
gui_ar1('reason');
gui_ar1('set_graphs');
watchoff(oldFigNumber);
elseif strcmp(action,'set_temp'),
% The value that has been typed into the box is checked for vality.
temp = str2num(get(Temp_Hndl,'String'));
set(Temp_Hndl,'String',num2str(temp));
elseif strcmp(action,'set_graphs'), % prepares the graphical output
axes(temp_axes);
plot_set(T,TEMP);
set(temp_axes,'NextPlot','add');
plot([temp temp],[0 1],'LineWidth',2);
text(1,1.1,'"COLD"','Fontsize',8);
text(17,1.1,'"NORMAL"','Fontsize',8);
text(31,1.1,'"HOT"','Fontsize',8);
set(temp_axes,'NextPlot','replace');
set(temp_axes,'YLim',[0 1.3],'XGrid','off','YGrid','off');
ylabel('Membership'); xlabel('Input : Temperature (degrees)');
text(0.12, 1.7,' Approximate Reasoning');
% text(0.12, 1.5,' Click and drag temp. line or sets');
axes(power_axes);
plot_set(P,POWER);
set(power_axes,'NextPlot','add');
% Fill output set:
if B(1) > 0, B(1)=0;end;
if B(length(B))>0, B(length(B))=0; end;
% fill(P,B,'w');
plot([output output],[0 1],'LineWidth',2);
plot([-100 100],[0 0],'w');
set(power_axes,'NextPlot','replace','XGrid','off','YGrid','off');
xlabel(['Output value = ',num2str(round(output))]); ylabel('Membership');
drawnow
elseif strcmp(action,'reason'),
% performs the approximate reasoning
% Fuzzification:
A=match(T,temp,TEMP);
cool=1; zero=2; heat=3;
RuleBank = [heat zero cool];
% Aggregation:
B=inferenc(A,POWER,RuleBank,infop);
B=accumulu(B,accop);
% Defuzzification:
output=sum(P*B')/sum(B);
elseif strcmp(action,'info'),
ttlStr = 'Approximate Reasoning';
hlpStr1= ...
[' '];
hlpStr2= ...
[' '];
hlpStr3= str2mat(...
' ', ...
' File name: gui_ar1.m');
helpfun(ttlStr, hlpStr1, hlpStr2, hlpStr3);
end; % of gui_ar1.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -