strrep6.m

来自「用MATLAB实现遗传算法中的好多问题」· M 代码 · 共 26 行

M
26
字号
% function s = strrep6(s1)
% 搜寻s1中 '/', '*', '^'并插入'.'
function s = strrep6(s1)
L=length(s1);
I = find(s1 == '*' | s1 == '/' | s1 == '^');
L_I=length(I);
 if L_I > 0,
    move_ind=zeros(1,1:L);
  t1=clock;
    for i=2:L_I,
       move_ind(I(i-1):I(i)-1)=zeros(1,I(i)-I(i-1))+(i-1);   
    end
  time3=etime(clock,t1);     
  t2=clock;
    move_ind(I(L_I):L)=zeros(1,L-I(L_I)+1)+(L_I);
    j=[1:L];
    s=blanks(L+L_I);
    s(j+move_ind)=s1(j);
    dot_ind=I+[0:L_I-1];
    s(dot_ind)=setstr(ones(1,length(dot_ind))*46);
  time4=etime(clock,t2);     
else,
    s=s1;   
end
 

⌨️ 快捷键说明

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