资源描述:
《交通流元胞自动机源代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、标准实用文案用Matlab实现元胞自动机(网上收集、转载)技术2010-03-1313:04:28阅读121评论0字号:大中小订阅.file:life.m%%初始化m=50;X=zeros(m,m);X(25,25)=1;n=[m1:m-1];e=[2:m1];s=[2:m1];w=[m1:m-1];%绘制初始图形[i,j]=find(X);figure(gcf);plothandle=plot(i,j,'.',...'Color','blue',...'MarkerSize',12);axis([0m+10m+1])
2、;%%演化fork=1:50%邻居数N=X(n,:)+X(s,:)+X(:,e)+X(:,w)+...X(n,e)+X(n,w)+X(s,e)+X(s,w);%概率阵文档标准实用文案RAND=rand(m);%换代X=X
3、(N.*RAND>0.99);%绘图[i,j]=find(X);set(plothandle,'xdata',i,'ydata',j)drawnowpause(0.2)kendfile2:functionsierpinski(n);%使用元胞自动机生成sierpinski直角垫片%Example:%s
4、ierpinski(256);%%算法见:孙博文,《分形算法与程序设计:用VisualC++实现》ifnargin==0;n=256;endX=ones(n);X(1,n-1)=0;H=imshow(X,[]);set(gcf,'doublebuffer','on');k=1;whilek5、CA_sim_cloud;%使用元胞自动机模拟地球卫星的云图%%reference:%Piazza,E.;Cuccoli,F.;%CellularAutomataSimulationofCloudsinSatelliteImages,%GeoscienceandRemoteSensingSymposium,2001.IGARSS'01.%IEEE2001InternationalVolume4,9-13July2001Page(s):%1722-1724vol.4DigitalObjectIdentifier10.11
6、09/IGARSS.%2001.977050time=888;%程序执行步数M=240;N=320;S=round(rand(M,N)*15);p=[1,2,1,6,6,1,2,1];p=sum(tril(meshgrid(p)),2)/20;rand('state',0);SS=S;R=rand(M,N);G=R;文档标准实用文案B=R;C=cat(3,R,G,B);fig=figure;set(fig,'DoubleBuffer','on');mov=avifile('example2.avi');cc=imsho
7、w(C,[]);set(gcf,'Position',[13355157194])x1=(1:3)+round(M/2);y1=(1:3)+round(N/3);x2=(1:3)+round(M/3);y2=(1:3)+round(N/2);x3=(1:3)+round(M/1.5);y3=(1:3)+round(N/2);q=0;qq=15/4;whileq
8、阵K(2:end-1,2:end-1)=T;SS=K(1:end-2,1:end-2).*(r
=p(1))+...K(1:end-2,3:end).*(r
=p(2))+...K(2:end-1,1:end-2).*(r
=p(3))+...K(2:end-1,3:end).*(r
=p(4))+...K(3:end,1:end-2).*(r
=p(5))+...K(3:end,2:e
9、nd-1).*(r
=p(6))+...K(3:end,3:end).*(r>=p(7))+SS;end文档标准实用文案S=SS;%SS是粒子扩散后的分布S(S>15)=15;S(x1,y1)=15;S(x2,y2)=15;S(x3,y3)=15;%粒子源赋值G=(S<=7.5);B=(S>qq);R=(S>qq&S