?? ruleview.m
字號(hào):
function ruleview(action, input, figNumber);
%RULEVIEW Rule viewer and fuzzy inference diagram.
% RULEVIEW(fis) opens the Rule Viewer, or Inference Diagram
% Viewer, for the fuzzy inference system, fis.
% RULEVIEW('FILENAME') depicts the fuzzy inference
% diagram for the fuzzy inference system stored in file
% FILENAME.FIS.
%
% The Rule Viewer displays, in one screen, all parts of
% the fuzzy inference process from inputs to outputs. Each
% row of plots corresponds to one rule, and each column of
% plots corresponds to either an input variable (yellow, on
% the left) or an output variable (blue, on the right). You
% can change the system input either by typing a specific
% value into the Input window or by moving the long yellow
% index lines that go down each input variable's column of
% plots.
%
% See also ADDRULE, MFEDIT, RULEEDIT, SURFVIEW
% Ned Gulley, 3-30-94 Kelly Liu 4-20-97, N. Hickey 03-17-01
% Copyright 1994-2004 The MathWorks, Inc.
% $Revision: 1.63.2.2 $ $Date: 2004/04/10 23:15:36 $
inputColor=[1 0 0];
outputColor=[0 0 1];
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
fis=action;
action='#initialize';
end;
if strcmp(action,'#initialize'),
fisName=fis.name;
numRules=length(fis.rule);
thisfis{1}=fis;
figNumber=figure( ...
'Name',['Rule Viewer: ' fisName], ...
'NumberTitle','off', ...
'IntegerHandle','off',...
'MenuBar','none', ...
'Visible','off', ...
'UserData',thisfis, ...
'Tag','ruleview', ...
'Color',[.9 .9 .9], ...
'DoubleBuffer', 'on', ...
'BackingStore','off', ...
'DockControls', 'off');
figPos=get(figNumber,'position');
%====================================
% The MENUBAR items
% Call fisgui to create the menubar items
fisgui #initialize
%===================================
% Information for all objects
frmColor=192/255*[1 1 1];
btnColor=192/255*[1 1 1];
editColor=255/255*[1 1 1];
border=6;
spacing=6;
maxRight=figPos(3);
maxTop=figPos(4);
btnWid=90;
btnHt=22;
bottom=border;
top=bottom+2*btnHt+5*spacing;
right=maxRight-border;
left=border;
%====================================
% The MAIN frame
% This frame is given a name so that it can be located later on
% using "findobj". The UserData for this frame will contain the
% matrix of line handles used in the callbacks.
name='dataframe';
frmBorder=spacing;
frmPos=[left-frmBorder bottom-frmBorder ...
right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
frmHndl=uicontrol( ...
'Style','frame', ...
'Units','pixel', ...
'Position',frmPos, ...
'Tag',name, ...
'BackgroundColor',frmColor);
%====================================
% The INPUT frame
top=top-spacing;
bottom=top-btnHt;
left=border+spacing;
right=maxRight-border-1.5*btnWid-5*spacing;
frmBorder=spacing;
frmPos=[left-frmBorder bottom-frmBorder ...
right-left-1.75*btnWid top-bottom+frmBorder*2]+[1 0 1 0];
topFrmHndl=uicontrol( ...
'Style','frame', ...
'Units','pixel', ...
'Position',frmPos, ...
'BackgroundColor',frmColor);
%-------numPts----------------------
frmPos=[right-frmBorder-1.75*btnWid+.5*spacing bottom-frmBorder ...
1.25*btnWid+1.5*spacing top-bottom+frmBorder*2]+[1 0 1 0];
topFrmHndl=uicontrol( ...
'Style','frame', ...
'Units','pixel', ...
'Position',frmPos, ...
'BackgroundColor',frmColor);
%------------------------------------
% The num of points text window
labelStr='Plot points:';
pos1=[right-frmBorder-1.75*btnWid+spacing*1 bottom .78*btnWid btnHt];
helpHndl=uicontrol( ...
'Style','text', ...
'BackgroundColor', frmColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos1, ...
'String',labelStr);
%------------------------------------
% The INPUT text window
labelStr='Input:';
pos=[left-spacing*.5 bottom btnWid/2 btnHt];
helpHndl=uicontrol( ...
'Style','text', ...
'BackgroundColor',frmColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos, ...
'String',labelStr);
%------------------------------------
% The INPUT edit window
callbackStr='ruleview #updateinputs';
name='inputdisp';
pos=[left+btnWid/2-2*spacing bottom right-left-btnWid*2.25 btnHt];
inputDispHndl=uicontrol( ...
'Style','edit', ...
'BackgroundColor',editColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos, ...
'Tag',name, ...
'Callback',callbackStr);
%------------------------------------
% The #points edit window
name='numdisp';
pos=[right-frmBorder-.85*btnWid-spacing*1 bottom .5*btnWid btnHt];
%pos1+[btnWid*.4 0 0 0];
inputDispHndl=uicontrol( ...
'Style','edit', ...
'BackgroundColor',editColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos, ...
'Callback', 'ruleview #update',...
'Tag',name);
%====================================
% The CLOSE/HELP frame
right=maxRight-border-spacing;
left=right-2*btnWid-spacing;
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);
frmPos=[left-frmBorder 7 ...
right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
clsFrmHndl=uicontrol( ...
'Style','frame', ...
'Units','pixel', ...
'Position',frmPos, ...
'BackgroundColor',frmColor);
%------------------------------------
% The postion text window
pos1=[right-frmBorder-2*btnWid-spacing*.5 bottom 1.5*btnWid btnHt];
helpHndl=uicontrol( ...
'Style','text', ...
'BackgroundColor',frmColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos1, ...
'String','Move:');
%------------------------------------
% The HELP button
labelStr='Help';
callbackStr='ruleview #help';
helpHndl=uicontrol( ...
'Style','push', ...
'Position',[left bottom-40 btnWid btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
%------------------------------------
% The CLOSE button
labelStr='Close';
callbackStr='fisgui #close';
closeHndl=uicontrol( ...
'Style','push', ...
'Position',[right-btnWid bottom-40 btnWid btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
%------------------------------------
% The shift horizontal button
labelStr='left';
callbackStr='ruleview #shiftleft';
left=left+37;
btnWid1= btnWid*2/5;
closeHndl=uicontrol( ...
'Style','push', ...
'Position',[left 53 btnWid*2/5 btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
% The shift horizontal button
labelStr='right';
callbackStr='ruleview #shiftright';
closeHndl=uicontrol( ...
'Style','push', ...
'Position',[left+38 53 btnWid1 btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
% The shift horizontal button
labelStr='down';
callbackStr='ruleview #shiftdown';
closeHndl=uicontrol( ...
'Style','push', ...
'Position',[left+76 53 btnWid1 btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
labelStr='up';
callbackStr='ruleview #shiftup';
closeHndl=uicontrol( ...
'Style','push', ...
'Position',[left+114 53 btnWid1 btnHt], ...
'BackgroundColor',btnColor, ...
'String',labelStr, ...
'Callback',callbackStr);
% callbackStr='ruleview #slidehori';
% closeHndl=uicontrol( ...
% 'Style','slide', ...
% 'Position',[20 90 3*btnWid btnHt], ...
% 'Max', 2,...
% 'Min', -2,...
% 'Value', 0, ...
% 'BackgroundColor',btnColor, ...
% 'String',labelStr, ...
% 'Callback',callbackStr);
%====================================
bottom=border+spacing;
% The STATUS frame
top=bottom+btnHt;
right=maxRight-border-2*btnWid-5*spacing;
left=border+spacing;
frmBorder=spacing;
frmPos=[left-frmBorder bottom-frmBorder ...
right-left+frmBorder*2 top-bottom+frmBorder*2]+[1 0 1 0];
dataFrmHndl=uicontrol( ...
'Style','frame', ...
'Units','pixel', ...
'Position',frmPos, ...
'BackgroundColor',frmColor);
%------------------------------------
% The STATUS text window
labelStr=['Opened system ' fisName ', ' num2str(numRules) ' rules'];
name='status';
pos=[left bottom right-left btnHt];
hndl=uicontrol( ...
'Style','text', ...
'BackgroundColor',frmColor, ...
'HorizontalAlignment','left', ...
'Units','pixel', ...
'Position',pos, ...
'Tag',name, ...
'String',labelStr);
ruleview #update
% Normalize all coordinates
hndlList=findobj(figNumber,'Units','pixels');
set(hndlList,'Units','normalized');
% Uncover the figure
set(figNumber, ...
'Visible','on', ...
'HandleVisibility','callback');
elseif strcmp(action,'#update'),
%====================================
figNumber=watchon;
oldfis=get(figNumber,'UserData');
fis=oldfis{1};
% Find and destroy all axes if they exist, since we might be updating
% a previously existing system
axHndlList=findobj(figNumber,'Type','axes');
delete(axHndlList);
set(figNumber,'Units','pixel')
inputDispHndl=findobj(figNumber,'Type','uicontrol','Tag','inputdisp');
set(inputDispHndl,'Enable','off');
% First some error-checking
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 (numInputs<1) | (numOutputs<1),
statmsg(figNumber,'Need at least one input and one output to view rules');
watchoff(figNumber)
return
end
numRules=length(fis.rule);
if numRules<1,
statmsg(figNumber,'Need at least one rule to view rules');
watchoff(figNumber)
return
end
border=6;
spacing=6;
btnHt=22;
figPos=get(figNumber,'Position');
maxRight=figPos(3);
maxTop=figPos(4);
axColor='black';
bottom=border;
top=bottom+2*btnHt+5*spacing;
right=maxRight-border;
% The mainAxPos is a border that defines where the rules will be displayed
% Getting it the right size was mostly trial and error
mainAxPos=[border top-bottom+border*6 maxRight-border*2 maxTop-top-border*10];
% Now build all the appropriate axes
% For each rule, there will be as many axes as (numInputs+numOutputs)
ruleList=getfis(fis, 'ruleList');
numRules=size(ruleList,1);
if isfield(fis, 'input')
numInputs=length(fis.input);
else
numInputs=0;
end
if isfield(fis, 'output')
numOutputs=length(fis.output);
else
numOutputs=0;
end
for i=1:numInputs
numInputMFs(i)=length(fis.input(i).mf);
end
for i=1:numOutputs
numOutputMFs(i)=length(fis.output(i).mf);
end
for i=1:numInputs
inRange(i, 1:2)=fis.input(i).range;
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -