⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ruleedit.m

📁 模糊控制工具箱,很好用的,有相应的说明文件,希望对大家有用!
💻 M
📖 第 1 页 / 共 3 页
字号:
        labelStr=showrule(fis,1:numRules,formatStr,lang);
    else
        labelStr=' ';
        msgStr=['No rules for system "' fisName '"'];
        statmsg(figNumber,msgStr);
    end
    set(hndl, 'Value', 1, 'String',labelStr);

    i=1;
    j=1;
    nameinHndl=[];
    nameoutHndl=[];
    tempinHndl=findobj(figNumber, 'Tag', ['ruleinmake' num2str(i)]);
    tempoutHndl=findobj(figNumber, 'Tag', ['ruleoutmake' num2str(i)]);
    if ~isempty(tempinHndl)
       nameinHndl(i)=tempinHndl;
    end
    if ~isempty(tempoutHndl)
       nameoutHndl(j)=tempoutHndl;
    end
    while ~isempty(tempinHndl)
     i=i+1;
     tempinHndl=findobj(figNumber, 'Tag', ['ruleinmake' num2str(i)]);
     if ~isempty(tempinHndl)
       nameinHndl(i)=tempinHndl;
     end
    end
    while ~isempty(tempoutHndl)
     j=j+1;
     tempoutHndl=findobj(figNumber, 'Tag', ['ruleoutmake' num2str(j)]);
     if ~isempty(tempoutHndl)
       nameoutHndl(j)=tempoutHndl;
     end
    end
    if (~isempty(nameinHndl))|(~isempty(nameoutHndl) )
      for k=1:length(nameinHndl)  
       tempradioHndl=findobj(figNumber, 'Tag', ['ruleinradio' num2str(k)]);
       templabelHndl=findobj(figNumber, 'Tag', ['ruleinlabel' num2str(k)]);
       tempkeywHndl=findobj(figNumber, 'Tag', ['ruleinkeyw' num2str(k)]);
       delete(tempradioHndl);
       delete(templabelHndl);
       delete(tempkeywHndl);
      end
      for k=1:length(nameoutHndl)  
       tempradioHndl=findobj(figNumber, 'Tag', ['ruleoutradio' num2str(k)]);
       templabelHndl=findobj(figNumber, 'Tag', ['ruleoutlabel' num2str(k)]);
       tempkeywHndl=findobj(figNumber, 'Tag', ['ruleoutkeyw' num2str(k)]);
       delete(tempradioHndl);
       delete(templabelHndl);
       delete(tempkeywHndl);
      end
       delete(nameoutHndl);
       delete(nameinHndl)
    end
    localAddrulemake(fis);
    shiftlHndl=findobj(figNumber, 'Tag', 'shiftleft'); 
    shiftrHndl=findobj(figNumber, 'Tag', 'shiftright'); 
    if isfield(fis, 'input') & isfield(fis, 'output')
      if length(fis.input)+length(fis.output)<6
        set(shiftlHndl, 'Enable', 'off');
        set(shiftrHndl, 'Enable', 'off');
      else
        set(shiftlHndl, 'Enable', 'on');
        set(shiftrHndl, 'Enable', 'on');
      end
    end
    watchoff(figNumber)

case '#disprules',
    %====================================
    figNumber=watchon;
    menuHndl=findobj(figNumber,'Type','uimenu','Tag','rulefrmt', 'Checked','on');
    dispStyle=lower(get(menuHndl,'Label'));
    dispStyle=deblank(dispStyle);
    dispStyle=fliplr(deblank(fliplr(dispStyle)));
    oldfis=get(figNumber,'UserData');
    fis=oldfis{1};
    numRules=length(fis.rule);
    if numRules==0,
        msgStr=['There are no rules for this system.'];
        statmsg(figNumber,msgStr);
    else
        msgStr=['Translating to ' dispStyle ' format'];
        statmsg(figNumber,msgStr);
        editHndl=findobj(figNumber,'Tag', 'rulewindow');
        langHndl=findobj(figNumber,'Type','uimenu','Tag', 'lang', 'Checked','on');
        lang=lower(get(langHndl,'Label'));
        editStr=showrule(fis,1:numRules,dispStyle,lang);
       % editStr=char([32*ones(size(editStr,1),1) editStr]);
        set(editHndl,'String',editStr);
    end
    watchoff(figNumber);
case '#langselect';
    %====================================
    figNumber=watchon;
    langSelectHndl=gcbo;
    langMenuHndl=get(langSelectHndl,'Parent');
    langUnselectHndl=findobj(langMenuHndl,'Checked','on');
    set(langUnselectHndl,'Checked','off');
    set(langSelectHndl,'Checked','on');
    ruleedit #disprules
    watchoff(figNumber)
case '#formatselect';
    %====================================
    figNumber=watchon;
    langSelectHndl=gcbo;
    langMenuHndl=get(langSelectHndl,'Parent');
    langUnselectHndl=findobj(langMenuHndl,'Checked','on');
    set(langUnselectHndl,'Checked','off');
    set(langSelectHndl,'Checked','on');
    ruleedit #disprules
    watchoff(figNumber)
case '#shiftright';
    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
    set(gcbf, 'Unit', 'normal');
    stop=0;
    for i=1:numInputs
     Hndl=findobj(gcbf, 'Tag', ['ruleinmake' num2str(i)]);
     radioHndl=findobj(gcbf, 'Tag', ['ruleinradio', num2str(i)]);
     labelHndl=findobj(gcbf, 'Tag', ['ruleinlabel', num2str(i)]);
     keyHndl=findobj(gcbf, 'Tag', ['ruleinkeyw', num2str(i)]);
     set(Hndl, 'Unit', 'normal');
     set(radioHndl, 'Unit', 'normal');
     set(labelHndl, 'Unit', 'normal');
     set(keyHndl, 'Unit', 'normal');

     pos=get(Hndl, 'Position');
     poslabel=get(labelHndl, 'Position');
     posradio=get(radioHndl, 'Position');
     poskey=get(keyHndl, 'Position');
     if i==1 & pos(1)>=.01
       stop=1;
       break
     end
     pos=pos+[.05, 0, 0, 0];
     posradio=posradio+[.05, 0, 0, 0];
     poslabel=poslabel+[.05, 0, 0, 0];
     poskey=poskey+[.05, 0, 0, 0];
     set(Hndl, 'Position', pos);
     set(radioHndl, 'Position', posradio);
     set(labelHndl, 'Position', poslabel);
     set(keyHndl, 'Position', poskey);
    end
    if stop==0
     for i=1:numOutputs
      Hndl=findobj(gcbf, 'Tag', ['ruleoutmake' num2str(i)]);
      radioHndl=findobj(gcbf, 'Tag', ['ruleoutradio', num2str(i)]);
      labelHndl=findobj(gcbf, 'Tag', ['ruleoutlabel', num2str(i)]);
      keyHndl=findobj(gcbf, 'Tag', ['ruleoutkeyw', num2str(i)]);
      set(Hndl, 'Unit', 'normal');
      set(radioHndl, 'Unit', 'normal');
      set(labelHndl, 'Unit', 'normal');
      set(keyHndl, 'Unit', 'normal');
      pos=get(Hndl, 'Position');
      poslabel=get(labelHndl, 'Position');
      posradio=get(radioHndl, 'Position');
      poskey=get(keyHndl, 'Position');
      pos=pos+[.05, 0, 0, 0];
      posradio=posradio+[.05, 0, 0, 0];
      poslabel=poslabel+[.05, 0, 0, 0];
      poskey=poskey+[.05, 0, 0, 0];
      set(Hndl, 'Position', pos);
      set(radioHndl, 'Position', posradio);
      set(labelHndl, 'Position', poslabel);
      set(keyHndl, 'Position', poskey);
     end
    end
case '#shiftleft';
    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
    set(gcbf, 'Unit', 'normal');
    lastone=numOutputs;
    stop=0;
    for i=lastone:-1:1
     Hndl=findobj(gcbf, 'Tag', ['ruleoutmake' num2str(i)]);
     radioHndl=findobj(gcbf, 'Tag', ['ruleoutradio', num2str(i)]);
     labelHndl=findobj(gcbf, 'Tag', ['ruleoutlabel', num2str(i)]);
     keyHndl=findobj(gcbf, 'Tag', ['ruleoutkeyw', num2str(i)]);
     set(Hndl, 'Unit', 'normal');
     set(radioHndl, 'Unit', 'normal');
     set(labelHndl, 'Unit', 'normal');
     set(keyHndl, 'Unit', 'normal');
     pos=get(Hndl, 'Position');
     poslabel=get(labelHndl, 'Position');
     posradio=get(radioHndl, 'Position');
     poskey=get(keyHndl, 'Position');
     if i==lastone & pos(1)<=1-pos(3)-.01
       stop=1;
       break
     end
     pos=pos-[.05, 0, 0, 0];
     posradio=posradio-[.05, 0, 0, 0];
     poslabel=poslabel-[.05, 0, 0, 0];
     poskey=poskey-[.05, 0, 0, 0];
     set(Hndl, 'Position', pos);
     set(radioHndl, 'Position', posradio);
     set(labelHndl, 'Position', poslabel);
     set(keyHndl, 'Position', poskey);
    end
    if stop==0
     lastone=numInputs;
     for i=1:lastone
      Hndl=findobj(gcbf, 'Tag', ['ruleinmake' num2str(i)]);
      radioHndl=findobj(gcbf, 'Tag', ['ruleinradio', num2str(i)]);
      labelHndl=findobj(gcbf, 'Tag', ['ruleinlabel', num2str(i)]);
      keyHndl=findobj(gcbf, 'Tag', ['ruleinkeyw', num2str(i)]);
     set(Hndl, 'Unit', 'normal');
     set(radioHndl, 'Unit', 'normal');
     set(labelHndl, 'Unit', 'normal');
     set(keyHndl, 'Unit', 'normal');
      pos=get(Hndl, 'Position');
      poslabel=get(labelHndl, 'Position');
      posradio=get(radioHndl, 'Position');
      poskey=get(keyHndl, 'Position');
      pos=pos-[.05, 0, 0, 0];
      set(Hndl, 'Position', pos);
      posradio=posradio-[.05, 0, 0, 0];
      poslabel=poslabel-[.05, 0, 0, 0];
      poskey=poskey-[.05, 0, 0, 0];
      set(radioHndl, 'Position', posradio);
      set(labelHndl, 'Position', poslabel);
      set(keyHndl, 'Position', poskey);
     end
    end
case '#add';
    thisact=get(gcbo, 'String');
    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

    errflag=1;                  %assume errflag=true
    sentence='if ';
    radioHndl=findobj(gcbf, 'Tag', 'radio');
    conn=2;
    for i=1:length(radioHndl)
       if get(radioHndl(i),'Value')~=0
         connStr=get(radioHndl(i),'String');
         if strcmp(connStr, 'and')
            conn=1;
         end
         break;
       end
    end
    for i=1:numInputs
      nameHndl=findobj(gcbf, 'Tag', ['ruleinmake' num2str(i)]);
      notHndl=findobj(gcbf, 'Tag', ['ruleinradio' num2str(i)]);
      if get(notHndl, 'Value')==0
        notvalue=1;
      else
        notvalue=-1;
      end
      value=get(nameHndl, 'Value');
      if value>length(fis.input(i).mf) %| ~isempty(fis.input(i).mf)
       str(i)=0;
      else
       str(i)=value*notvalue;
       errflag=0;       
      end
    end
   if errflag==0,
    errflag=1;
    for i=1:numOutputs
      nameHndl=findobj(gcbf, 'Tag', ['ruleoutmake' num2str(i)]);
      notHndl=findobj(gcbf, 'Tag', ['ruleoutradio' num2str(i)]);
      if get(notHndl, 'Value')==0
         notvalue= 1;
      else
         notvalue=-1;
      end
      value=get(nameHndl, 'Value');
      if value>length(fis.output(i).mf) %| ~isempty(fis.output(i).mf)
        str(numInputs+i) = 0;
      else
        str(numInputs+i)=value*notvalue;
       errflag=0;
      end
       
    end
   end
   if errflag==0;
    weightHndl=findobj(gcbf, 'tag', 'weight');
    weight=get(weightHndl, 'String'); 
   
    ruleHndl=findobj(gcbf, 'tag', 'rulewindow');
    if isempty(str2double(weight))
       wght=1;
    else
       wght=max(min(str2double(weight), 1), 0);
    end
    if strcmp(thisact, 'Add rule')
      index=length(fis.rule)+1;
      statusStr='added';
    else
     index=get(ruleHndl, 'Value');
      statusStr='changed';
    end 
    fis.rule(index).antecedent=str(1:numInputs);
    fis.rule(index).consequent=str(numInputs+1:end);
    fis.rule(index).weight=wght;
    fis.rule(index).connection=conn;
    if length(fis.rule)~=0
       delHndl=findobj(gcbf, 'Tag', 'delete');
       set(delHndl, 'Enable', 'on');
    end
    updtfis(gcbf,fis,[4 5]);
    pushundo(gcbf,fis);
    formatHndl=findobj(gcbf,'Type','uimenu','Tag','rulefrmt', 'Checked','on');
    formatStr=lower(get(formatHndl,'Label'));
    formatStr=deblank(formatStr);
    formatStr=fliplr(deblank(fliplr(formatStr)));
    langHndl=findobj(gcbf,'Type','uimenu', 'Tag', 'lang', 'Checked','on');
    lang=lower(get(langHndl,'Label'));
    lang=deblank(lang);
    lang=fliplr(deblank(fliplr(lang)));
    thisrule=showrule(fis,1:length(fis.rule), formatStr, lang); 
    set(ruleHndl,'String', thisrule, 'value', index);
    statusHndl=findobj(gcbf, 'Tag', 'status');
    set(statusHndl, 'String', ['The rule is ' statusStr]);
   else
    statusHndl=findobj(gcbf, 'Tag', 'status');
    set(statusHndl, 'String', 'The rule is incomplete');
   end
case '#delete';
    oldfis=get(gcbf, 'Userdata');
    fis=oldfis{1};
    if ~isfield(fis, 'rule') | length(fis.rule)==0
       delHndl=findobj(gcbf, 'Tag', 'delete');
       set(delHndl, 'Enable', 'off');
       return;
    end
    ruleHndl=findobj(gcbf, 'tag', 'rulewindow');
    thisrule=get(ruleHndl, 'String');
    index=get(ruleHndl, 'Value');
    thisrule(index, :)=[];
    fis.rule(index)=[];
    if length(fis.rule)==0
       delHndl=findobj(gcbf, 'Tag', 'delete');
       set(delHndl, 'Enable', 'off');
    end
    thisfis{1}=fis;
    if index>size(thisrule,1)
     set(ruleHndl, 'Value', max(1, index-1));
    end
    statusHndl=findobj(gcbf, 'Tag', 'status');
    set(statusHndl, 'String', 'The rule is deleted');
    pushundo(gcbf,fis);

    updtfis(gcbf,fis,[4 5]);
    formatHndl=findobj(gcbf,'Type','uimenu','Tag','rulefrmt', 'Checked','on');
    formatStr=lower(get(formatHndl,'Label'));
    formatStr=deblank(formatStr);
    formatStr=fliplr(deblank(fliplr(formatStr)));
    langHndl=findobj(gcbf,'Type','uimenu', 'Tag', 'lang', 'Checked','on');
    lang=lower(get(langHndl,'Label'));
    lang=deblank(lang);
    lang=fliplr(deblank(fliplr(lang)));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -