代码来自《元胞自动机与MATLAB》,是元胞自动机中“生命游戏”模型的代码核心代码:x=2:n-1;y=2:n-1;sum(x,y)=cells(x,y-1)+cells(x,y+1)+cells(x-1,y)+cells(x+1,y)+cells(x-1,y-1)+cells(x-1,y+1)+cells(x+1,y-1)+cells(x+1,y+1);cells=(sum==3)|(sum==2&cells);%%%%此处出错运行部分:while(stop==0)if(run==1)%nearestneighborsumsum(x,y)=cells(x,y-1)+cells(x,y+1)+%%%此处出错cells(x-1,y)+cells(x+1,y)+cells(x-1,y-1)+cells(x-1,y+1)+cells(3:n,y-1)+cells(x+1,y+1);%TheCArulecells=(sum==3)|(sum==2&cells);%drawthenewimageset(imh,'cdata',cat(3,cells,z,z))%updatethestepnumberdiaplaystepnumber=1+str2num(get(number,'string'));set(number,'string',num2str(stepnumber))endif(freeze==1)run=0;freeze=0;enddrawnow%needthisintheloopforcontrolstoworkend