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

📄 anfsedit.m

📁 模糊控制工具箱,很好用的,有相应的说明文件,希望对大家有用!
💻 M
📖 第 1 页 / 共 2 页
字号:
         fismat=genfis1(trnData, inmflist, mfType);
         fismat.type=fis.type;
         fismat.name=fis.name;
         fismat.andMethod = fis.andMethod;
         fismat.orMethod = fis.orMethod;
         fismat.defuzzMethod =fis.defuzzMethod;
         fismat.impMethod = fis.impMethod;
         fismat.aggMethod = fis.aggMethod;
      else
         fismat=genfis2(trnData(:,1), trnData(:,2), .2);
      end
      if isfield(fis, 'tstData')
         fismat.tstdata=fis.tstData;
      end 
      fismat.trndata=fis.trndata;
      
      textHndl=findobj(gcf, 'Tag', 'Comments');
      % textstr=get(textHndl, 'String');
      textstr=['input number: ' num2str(length(fis.input)) 'output number: ' num2str(length(fis.output))];
      set(textHndl, 'String', textstr);
      set(figNumber, 'Userdata', fismat);
      updtfis(figNumber,fismat,[6]);
      LocalEnableBtns(fismat);  
      
   end
   %=======plot anfis structure=========     
elseif strcmp(action,'#plotstruc'),
   fis=get(gcbf, 'Userdata');
   plotFig=findobj('type', 'figure', 'Name', 'Anfis Structure');
   
   if isempty(plotFig)
      plotFig=figure('Name', 'Anfis Structure',...
         'Unit', 'normal',...
         'WindowButtonDownFcn', 'anfisedit #showparam',...
         'WindowButtonUpFcn', 'anfisedit #clearparam',...
         'NumberTitle','off',...
         'Tag', 'plotstruc');
      axis off;
      
   end
   gcf=plotFig;
   TextHndl=uicontrol('Style',  'text', 'Unit', 'normal', 'Position', [0 0 .1 .020], 'Tag', 'strcparam');
   plotFigChild=get(plotFig, 'children');
   axHndl=[];
   for i=1:length(plotFigChild)
      if strcmp(get(plotFigChild(i), 'type'),'axes')
         axHndl = plotFigChild(i);
      end
   end
   if ~isempty(axHndl)
      axes(axHndl);
   end 
   set(gca, 'XLimMode', 'Manual', 'Xlim', [0 .8], 'Ylim', [-0.1 1]);
   pos=get(plotFig, 'Position');
   % str={'input', 'input mf', 'rules', 'output mf','', 'output'};
   
   %for i=1:6
   %    text(.1*i, -0.02, str(i));
   % end
   instep=1/(length(fis.input)+1);
   for i=1:length(fis.input)
      line([.1], [instep*i], 'marker', 'o', 'MarkerSize', 15, 'color', 'red');
      mfstep=instep/(length(fis.input(i).mf)+1);
      for j=1:length(fis.input(i).mf)
         line([.2], [(i-1/2)*instep+mfstep*j], 'marker', 'o', 'MarkerSize', 15, 'color', 'blue');
         line([.1 .2], [instep*i (i-1/2)*instep+mfstep*j], 'color', 'black');
      end  
   end
   rulestep=1/(length(fis.rule)+1);
   rulecolor={'blue', 'red'};
   for i=1:length(fis.rule)
      temp=rulestep*i;
      line([.3], [temp], 'marker', 'o', 'MarkerSize', 15, 'color', 'red');
      line([.4], [temp], 'marker', 'o', 'MarkerSize', 15, 'color', 'blue');
      line([.3 .4], [temp temp], 'color', 'black');
      line([.3 .4], [temp .05], 'color', 'black');
      conn=fis.rule(i).connection;
      for j=1:length(fis.rule(i).antecedent)
         ruleindex=fis.rule(i).antecedent(j);
         if ruleindex~=0
            if conn==-1 
               thiscolor='green';
            else
               thiscolor=rulecolor(conn);
            end
            mfstep=instep/(length(fis.input(j).mf)+1);
            line([.2 .3], [(j-1/2)*instep+mfstep*ruleindex rulestep*i], 'color', char(thiscolor));
         end
      end  
   end
   
   outstep=1/(length(fis.output)+1);
   for i=1:length(fis.output)
      line([.5], [outstep*i], 'marker', 'o', 'MarkerSize', 15, 'color', 'red');
      for j=1:length(fis.rule)
         line([.4 .5], [rulestep*j outstep*i], 'color', 'black');
      end
   end
   line([.4], [.05], 'marker', 'o', 'MarkerSize', 15, 'color', 'red');
   line([.6], [outstep*(i)/2], 'marker', 'o', 'MarkerSize', 15, 'color', 'red');
   line([.5 .6], [outstep*(i) outstep*(i)/2], 'color', 'red');
   line([.4 .6], [.05 outstep*(i)/2],'color', 'red');
   
   line ([.7 .75], [0.5 0.5], 'Color', 'red');
   text(.77, .49, 'and');
   line ([.7 .75], [.6 0.6], 'Color', 'blue');
   text(.77, .59, 'or');
   line ([.7 .75], [0.7 0.7], 'Color', 'green');
   text(.77, .69, 'not');
   %=======mouse down function for plotting structure=========
elseif strcmp(action, '#showparam'),
   FigNumber=findobj(0, 'Type', 'figure', 'Tag','anfisedit');
   fis=get(FigNumber, 'Userdata'); 
   plotFig=findobj('type', 'figure', 'Name', 'Anfis Structure');
   set(plotFig, 'Unit', 'normal');
   pt=get(gca,'currentpoint');
   x=pt(1,1);
   y=pt(1,2);
   
   instep=1/(length(fis.input)+1);
   showparam=0;
   showstr=[];
   for i=1:length(fis.input)
      if x>.1-.02 & x<.1+.02 & y>instep*i-.02 & y<instep*i+.02
         showparam=1;
         showstr=['Input ' num2str(i)];
         break;
      else
         mfstep=instep/(length(fis.input(i).mf)+1);
         for j=1:length(fis.input(i).mf)
            thisy=(i-1/2)*instep+mfstep*j;
            if x>.2-.02 & x<.2+.02 & y>thisy-.02 & y<thisy+.02
               showparam=1;
               showstr=['Input mf ' num2str(j) ' of input ' num2str(i) ' ' fis.input(i).mf(j).name];
               
               break;
            end
         end
      end   
   end
   rulestep=1/(length(fis.rule)+1);
   if showparam==0
      for i=1:length(fis.rule)
         temp=rulestep*i;
         if x>.3-.02 & x<.3+.02 & y>temp-.02 & y<temp+.02
            showparam=1;
            showstr=['rule ' num2str(i)];
            break
         elseif x>.4-.02 & x<.4+.02 & y>temp-.02 & y<temp+.02
            showparam=1;
            showstr=['output mf ' num2str(fis.rule(i).consequent(1))];
            break
         end
      end
   end
   if showparam==0
      
      outstep=1/(length(fis.output)+1);
      for i=1:length(fis.output)
         temp=outstep*i/2;
         if x>.6-.02 & x<.6+.02 & y>temp-.02 & y<temp+.02
            showparam=1;
            showstr=['output ' num2str(i)];
         end
      end
   end
   
   if showparam==1
      textHndl=findobj(plotFig, 'Tag', 'strcparam');
      set(textHndl,'String', showstr, 'Position', [x y .2 .080], 'Visible', 'on');
   end   
   %============== mouse up function for plotting structure===============
elseif strcmp(action, '#clearparam'),
   plotFig=findobj('type', 'figure', 'Name', 'Anfis Structure');
   textHndl=findobj(plotFig, 'Tag', 'strcparam');
   set(textHndl, 'Visible', 'off');
   %========open training set file================                
elseif strcmp(action,'#opentrn'),
   % open an existing file
   fis=get(gcbf,'UserData'); 
   if isempty(fis)
      msgbox(' No fuzzy system, specify input number and output number through fuzzy editor');
   else
      inNum=length(fis.input);
      outNum=length(fis.output);
      [fname, fpath]=uigetfile('*.dat'); 
      
      if isstr(fname)&isstr(fpath)
         fid=fopen([fpath fname]);
         trndata=fscanf(fid, '%f', [inNum+outNum,inf])';
         fis.trndata=trndata;
         trn_num=['Number of training data pairs: ' num2str(size(trndata,1))];
         textHndl=findobj(gcbf, 'Tag', 'Comments');
         %  textstr=get(textHndl, 'String');
         set(textHndl, 'String', trn_num);
         set(gcbf, 'UserData', fis); 
      end  
      LocalEnableBtns(fis);  
      
   end
elseif strcmp(action,'#opentst'),
   fis=get(gcf,'UserData'); 
   [fname, fpath]=uigetfile; 
   
   if isstr(fname)&isstr(fpath)
      fid=fopen([fpath fname]);
      tstdata=fscanf(fid, '%f', [length(fis.input)+length(fis.output),inf])';
      fis.tstdata=trndata;
      set(gcf, 'UserData', fis);   
   end
   
   
elseif strcmp(action,'#test'),
   fis=get(gcbf,'UserData');
   testHndl=findobj(gcbf, 'Tag', 'test');
   n=get(testHndl, 'Value');
   cla
   if n==1
      if isfield(fis, 'trndata')
         testdata=fis(1).trndata;
      else
         msgbox('no training data');
         testdata=[];
      end
   else
      if isfield(fis, 'tstdata')
         testdata=fis(1).tstdata;
      else
         msgbox('no testing data');
         testdata=[];
      end
      
   end
   if ~isempty(testdata)
      datasize=size(testdata, 1);
      inputnum=size(testdata, 2)-1;
      targetdata=fis(1).trndata(1:datasize, inputnum+1);
      testOut=evalfis(testdata(1:datasize, 1:inputnum), fis(1));
      targetlineHndl=line([1:datasize],targetdata, 'lineStyle', 'none', 'Marker', 'o'); 
      testlineHndl=line([1:datasize],testOut); 
   end
end;    % if strcmp(action, ...
% End of function anfisedit

%==================================================
function LocalEnableBtns(fis)
% control the enable property for buttons
startHndl = findobj(gcf, 'Tag', 'startbtn');

if ~isfield(fis, 'trndata')| isempty(fis.trndata(1)) 
   %| 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(gcf, 'Tag', 'plotstrc');
testHndl = findobj(gcf, 'Tag', 'test');
if  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 editable text 
uiHandle=uicontrol( ...
   'Style',uiStyle, ...
   'HorizontalAlignment','left', ...
   'Units','normalized', ...
   'Max',20, ...
   'BackgroundColor',[1 1 1], ...
   'Position',uiPos, ...
   'Callback',uiCallback, ... 
'Tag', uiTag, ...
   'String',promptStr);

%==================================================
function frmHandle=LocalBuildFrmTxt(frmPos, txtStr, uiStyle, txtTag)
% build frame and label
frmHandle=uicontrol( ...
   'Style', uiStyle, ...
   'Units','normalized', ...
   'Position',frmPos, ...
   'BackgroundColor',[0.50 0.50 0.50], ...
   'ForegroundColor',[1 1 1], ...                  %generates an edge
'String', txtStr, ...
   'Tag', txtTag);

%==================================================
function btHandle=LocalBuildBtns(thisstyle, btnNumber, labelStr, callbackStr, uiTag)
% build buttons or check boxes

labelColor=[0.8 0.8 0.8];
top=0.95;
left=0.80;
btnWid=0.15;
btnHt=0.06;
bottom=0.03;
% 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); 

%==================================================

⌨️ 快捷键说明

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