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

📄 n_simp2.m

📁 遗传算法的matlab程序集(内有很多问题的具体解决程序)
💻 M
字号:
% function y=n_simp2(x)
%
% Simplifies strings from tree_ga2 etc.
%
% Input
%       x - population matrix
% Output
%       y - simplified population martrix

function y_pop=n_simp2(x_pop)
 
[Q,R]=size(x_pop);

for i=1:Q, 
   x=x_pop(i,:);
%   x=simple(x);
   x=strrep(x,'[','');
   x=strrep(x,']','');
   x=strrep(x,'--','+');
   x=strrep(x,'-+','-');
   x=strrep(x,'+-','-');
   x=strrep(x,'++','+');
   x=strrep(x,'*-','*<-');

   % Find all <'s, index them and replace them with ('s
   I=findstr(x,'<');
   new_x=x;
   while I~=[],
      x=strrep(x,'*<-','*(-');
      new_x=x;
      R=length(x);
      % Find correct position for matching )
      for j=1:length(I),
         for k=I(j)+2:R,
            if any(x(k)==['+-/*^'])==1 & x(k-1)~=['e'],
                new_x=[new_x(1:k+j-1-1) ')' new_x(k+j-1-1+1:R+j-1)];
                break
            end
         end
      end
 %     x=simple(x);
      x=strrep(x,'--','+');
      x=strrep(x,'-+','-');
      x=strrep(x,'+-','-');
      x=strrep(x,'++','+');
      x=strrep(x,'*-','*<-');
      I=findstr(x,'<');
   end
   x=strrep(new_x,'p','exp');
   x=strrep(x,'l','log');
   x=strrep(x,'r','sqrt');
   if i==1,
      y_pop=x;
   else
      y_pop=str2mat(y_pop,x);
   end
end

⌨️ 快捷键说明

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