gusucode.com > 《模式识别与智能计算》matlab源代码 > 《模式识别与智能计算》matlab源代码/《模式识别与智能计算》部分函数的源程序/书程序/第9章/gamutation1.m

    function [new,nmut]=gamutation1(pop,pm)
[popsize,genelen]=size(pop);
nmut=0;
for i=1:popsize
    for j=1:genelen
        test=rand;
        if test<pm
          a=fix(rand*3+1);
           while a==pop(i,j);
               a=fix(rand*3+1);
           end
           pop(i,j)=a;
        end
    end
end
new=pop;