📄 ruleedit.m
字号:
thisrule=showrule(fis,1:length(fis.rule), formatStr, lang);
set(ruleHndl,'String', thisrule, 'value', max(1, index-1));
case '#radio';
thisradio=gcbo;
set(thisradio, 'Value', 1);
radioHndl=findobj(gcbf, 'Tag', 'radio');
for i=1:length(radioHndl)
if thisradio~=radioHndl(i)
set(radioHndl(i), 'Value', 0);
end
end
oldfis=get(gcbf, 'Userdata');
fis=oldfis{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
keyword=get(thisradio, 'String');
for i=2:numInputs
keyHndl(i)=findobj(gcbf, 'Tag', ['ruleinkeyw' num2str(i)]);
set(keyHndl(i), 'String', keyword);
end
for i=2:numOutputs
keyHndl(i)=findobj(gcbf, 'Tag', ['ruleoutkeyw' num2str(i)]);
set(keyHndl(i), 'String', keyword);
end
case '#getrule';
index=get(gcbo, 'Value');
oldfis=get(gcbf, 'Userdata');
fis=oldfis{1};
figNumber=gcbf;
localgetrule(figNumber, index, fis)
case '#help';
%====================================
figNumber=watchon;
helpwin(mfilename);
watchoff(figNumber)
end; % if strcmp(action, ...
function localAddrulemake(fis)
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 isfield(fis, 'rule')
numRules=length(fis.rule);
else
numRules=0;
end
% Information for all objects
frmColor=192/255*[1 1 1];
btnColor=192/255*[1 1 1];
popupColor=192/255*[1 1 1];
editColor=255/255*[1 1 1];
axColor=128/255*[1 1 1];
border=.01;
spacing=.01;
figPos=get(0,'DefaultFigurePosition');
maxRight=1;
maxTop=1;
btnWid=.14;
btnHt=0.05;
bottom=border+4*spacing+btnHt;
top=bottom+btnHt;
bottom=top+3*spacing;
top=maxTop-border-spacing;
right=maxRight-border-spacing;
left=border+spacing;
frmBorder=spacing;
%------------------------------------
% The RULES edit window1
boxHeight=(top-bottom)*1/4;
boxDstn=(right-left)/5;
boxWidth=(right-left)/6;
boxShiftY=(bottom+top)/8;
for i=0:numInputs-1
rulePos=[left+i*boxDstn bottom+boxShiftY boxWidth boxHeight];
if numRules>0,
labelStr=' ';
else
labelStr=' ';
msgStr=['No rules for system "' fis.name '"'];
statmsg(gcf,msgStr);
end
name=['ruleinmake' num2str(i+1)];
if isfield(fis.input(i+1), 'mf') & ~isempty(fis.input(i+1).mf)
str=getfis(fis, 'input', i+1, 'mflabels');
str=strvcat(str, 'none');
else
str=[];
end
ruleHndl=uicontrol( ...
'Style','listbox', ...
'Units','normal', ...
'Position',rulePos, ...
'BackgroundColor',editColor, ...
'HorizontalAlignment','left', ...
'Max',1, ...
'String', str,...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing, 0, btnHt*2/3-boxHeight];
name=['ruleinlabel' num2str(i+1)];
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', [fis.input(i+1).name ' is'],...
'HorizontalAlignment','center', ...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing+btnHt*2/3, 0, btnHt*2/3-boxHeight];
name=['ruleinkeyw' num2str(i+1)];
if i==0
strname='If';
else
strHndl=findobj(gcf, 'Tag', 'radio');
if get(strHndl(1), 'Value')==1
strname=get(strHndl(1), 'String');
else
strname=get(strHndl(2), 'String');
end
end
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', strname,...
'HorizontalAlignment','left', ...
'Tag',name);
pos=rulePos+[0, -btnHt, 0, btnHt-boxHeight];
helpHndl=uicontrol( ...
'Style','checkbox', ...
'Units','normal', ...
'Position',pos, ...
'BackgroundColor',btnColor, ...
'String','not', ...
'Tag', ['ruleinradio' num2str(i+1)],...
'Max', 1,...
'Value', 0);
end
endedge=left+(numInputs+numOutputs)*boxDstn+boxWidth;
if endedge>maxRight-left
%out of border
left1=left+numInputs*boxDstn;
for i=0:numOutputs-1
rulePos=[left1+i*boxDstn bottom+boxShiftY boxWidth boxHeight];
name=['ruleoutmake' num2str(i+1)];
if isfield(fis.output(i+1), 'mf') & ~isempty(fis.output(i+1).mf)
str=getfis(fis, 'output', i+1, 'mflabels');
str=strvcat(str, 'none');
else
str=[];
end
ruleHndl=uicontrol( ...
'Style','listbox', ...
'Units','normal', ...
'Position',rulePos, ...
'BackgroundColor',editColor, ...
'HorizontalAlignment','left', ...
'String', str,...
'Max',1, ...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing, 0, btnHt*2/3-boxHeight];
name=['ruleoutlabel' num2str(i+1)];
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', [fis.output(i+1).name ' is'],...
'HorizontalAlignment','center', ...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing+btnHt*2/3, 0, btnHt*2/3-boxHeight];
name=['ruleoutkeyw' num2str(i+1)];
if i==0
strname='Then';
else
strHndl=findobj(gcf, 'Tag', 'radio');
if get(strHndl(1), 'Value')==1
strname=get(strHndl(1), 'String');
else
strname=get(strHndl(2), 'String');
end
end
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', strname,...
'HorizontalAlignment','left', ...
'Tag',name);
pos=rulePos+[0, -btnHt, 0, btnHt-boxHeight];
helpHndl=uicontrol( ...
'Style','checkbox', ...
'Units','normal', ...
'Position',pos, ...
'BackgroundColor',btnColor, ...
'String','not', ...
'Tag', ['ruleoutradio' num2str(i+1)],...
'Max', 1,...
'Value', 0);
end
else
for i=1:numOutputs
outIndex=numOutputs+1;
rulePos=[maxRight-i*boxDstn bottom+boxShiftY boxWidth boxHeight];
name=['ruleoutmake' num2str(outIndex-i)];
if isfield(fis.output(outIndex-i), 'mf') & ~isempty(fis.output(outIndex-i).mf)
str=getfis(fis, 'output', outIndex-i, 'mflabels');
str=strvcat(str, 'none');
else
str=[];
end
ruleHndl=uicontrol( ...
'Style','listbox', ...
'Units','normal', ...
'Position',rulePos, ...
'BackgroundColor',editColor, ...
'HorizontalAlignment','left', ...
'String', str,...
'Max',1, ...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing, 0, btnHt*2/3-boxHeight];
name=['ruleoutlabel' num2str(outIndex-i)];
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', [fis.output(outIndex-i).name ' is'],...
'HorizontalAlignment','center', ...
'Tag',name);
textPos=rulePos+[0, boxHeight+spacing+btnHt*2/3, 0, btnHt*2/3-boxHeight];
name=['ruleoutkeyw' num2str(outIndex-i)];
if numOutputs==i
strname='Then';
else
strHndl=findobj(gcf, 'Tag', 'radio');
if get(strHndl(1), 'Value')==1
strname=get(strHndl(1), 'String');
else
strname=get(strHndl(2), 'String');
end
end
textHndl=uicontrol( ...
'Style','text', ...
'Units','normal', ...
'Position',textPos, ...
'BackgroundColor',frmColor, ...
'String', strname,...
'HorizontalAlignment','left', ...
'Tag',name);
pos=rulePos+[0, -btnHt, 0, btnHt-boxHeight];
helpHndl=uicontrol( ...
'Style','checkbox', ...
'Units','normal', ...
'Position',pos, ...
'BackgroundColor',btnColor, ...
'String','not', ...
'Tag', ['ruleoutradio' num2str(outIndex-i)],...
'Max', 1,...
'Value', 0);
end
end
function localgetrule(figNumber, index, fis)
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 isfield(fis, 'rule')
rulelist=fis.rule;
else
rulelist=[];
end
if isempty(rulelist)
return;
end
radioHndl=findobj(figNumber, 'Tag', 'radio');
weightHndl=findobj(figNumber, 'Tag', 'weight');
% for i=2:numInputs
% connectw(i-1)=findobj(figNumber, 'Tag', ['ruleinkeyw' num2str(i)]);
% end
connect=fis.rule(index).connection;
weight=fis.rule(index).weight;
% for i=1:0 %length(connectw)
% if connect==1
% set(connectw(i), 'String', 'and')
% else
% set(connectw(i), 'String', 'or')
% end
% end
if connect==1
set(radioHndl(1), 'value', 0);
set(radioHndl(2), 'value', 1);
else
set(radioHndl(1), 'value', 1);
set(radioHndl(2), 'value', 0);
end
set(weightHndl, 'String', num2str(weight));
for i=1:numInputs
Hndl=findobj(figNumber, 'Tag', ['ruleinmake' num2str(i)]);
rulevarindex=rulelist(index).antecedent(i);
if rulevarindex==0
set(Hndl, 'Value', length(fis.input(i).mf)+1);
else
notHndl=findobj(figNumber, 'Tag', ['ruleinradio' num2str(i)]);
if rulevarindex<0
set(notHndl, 'Value', 1);
rulevarindex=-rulevarindex;
else
set(notHndl, 'Value', 0);
end
set(Hndl, 'Value', rulevarindex);
end
end
for i=1:numOutputs
Hndl=findobj(figNumber, 'Tag', ['ruleoutmake' num2str(i)]);
rulevarindex=rulelist(index).consequent(i);
if rulevarindex==0
set(Hndl, 'Value', length(fis.output(i).mf)+1);
else
notHndl=findobj(figNumber, 'Tag', ['ruleoutradio' num2str(i)]);
if rulevarindex<0
set(notHndl, 'Value', 1);
rulevarindex=-rulevarindex;
else
set(notHndl, 'Value', 0);
end
set(Hndl, 'Value', rulevarindex);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -