Cellular Automata in Matlab.docx

上传人:王** 文档编号:1334170 上传时间:2024-06-19 格式:DOCX 页数:13 大小:76.27KB
下载 相关 举报
Cellular Automata in Matlab.docx_第1页
第1页 / 共13页
Cellular Automata in Matlab.docx_第2页
第2页 / 共13页
Cellular Automata in Matlab.docx_第3页
第3页 / 共13页
Cellular Automata in Matlab.docx_第4页
第4页 / 共13页
Cellular Automata in Matlab.docx_第5页
第5页 / 共13页
Cellular Automata in Matlab.docx_第6页
第6页 / 共13页
Cellular Automata in Matlab.docx_第7页
第7页 / 共13页
Cellular Automata in Matlab.docx_第8页
第8页 / 共13页
Cellular Automata in Matlab.docx_第9页
第9页 / 共13页
Cellular Automata in Matlab.docx_第10页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Cellular Automata in Matlab.docx》由会员分享,可在线阅读,更多相关《Cellular Automata in Matlab.docx(13页珍藏版)》请在优知文库上搜索。

1、CellularAutomatainMatlabIntroductionCellularAutomata(CA)areaschemeforcomputingusinglocalrulesandlocalcommunication.TypicallyaCAisdefinedonagrid,witheachpointonthegridrepresentingacellwithafinitenumberofstates.Atransitionruleisappliedtoeachcellsimultaneously.Typicaltransitionrulesdependonthestateofth

2、ecellandits(4or8)nearestneighbors,althoughotherneighborhoodsareused.CAshaveapplicationsinparallelcomputingresearch,physicalsimulations,andbiologicalsimulations.ThispagewillconsiderhowtowriteefficientmatlabcodetoimplementCAsandlookatsomeinterestingrules.codemakesuseofMatlab,sveryflexibleindexingtospe

3、cifythenearestneighbors. x=2:n-l; y-2:n-l; sum(x,y)=cells(x,y-l)+cells(x,y+l)+. cells(x-l,y)+cells(x+l,y)+. cells(x-l,y-l)+cells(-l,y+l)+ cells(x+l,y-l)+cells(x+l,y+l); cells=(sum=3)(sum=2&cells); AddingasimpleGUIiseasy.Inthisexamplethreebuttonsandatextfieldwereimplmented.Thethreebuttonsallowauserto

4、Run,Stop,orQuit.Thetextfielddisplaysthenumberofsimulationstepsexecuted. %buildtheGUI %definetheplotbutton plotbutton=uicontrol(,style,pushbutton,. ,string,Run, ,fontsize,12, ,position,100,400,50,20,. ,callback,run=l;,); %definethestopbutton erasebutton-uicontrol(style,pushbutton1,. ,string,Stop, ,fo

5、ntsize,12, ,position,200,400,50,20,. ,callback,freeze=l;,); %definetheQuitbutton quitbutton=uicontrol(style,pushbutton,. ,string,Quit, ,fontsize,12, ,position,300,400,50,20, ,callback*,stop=l;close/); number=uicontrol(,style,text, ,string*,1, ,fontsize,12, ,position,20,400,50,20);Afterthecontrols(an

6、dCA)areinitialized,theprogramdropsintoaloopwhichteststhestateofthevariableswhicharesetinthecallbackfunctionsofeachbutton.Forthemoment,justlookatthenestedstructureofthewhileloopandifstatements.TheprogramloopsuntiltheQuitbuttonispushed.Theothertwobuttonscauseanifstatementtoexecutewhenpushed.stop=0;%wa

7、itforaquitbuttonpushrun=0;%waitforadrawfreeze=0;%waitforafreezewhile(StoP=O)if(run=l)%nearestneighborsumsum(x,y)二cells(x,y-l)+cells(x,y+l)+.cells(-l,y)+cells(x+l,y)+.cells(-l,y-l)+cells(-l,y+l)+.cells(3:n,y-l)+cells(x+l,y+l);%TheCArulecells=(SUnI=3)(SUm=2&cells);%drawthenewimageset(imh,cdata,cat(3,c

8、ells,z,z)%updatethestepnumberdiaplaystepnumber=1str2num(get(number,string,);set(number,string,num2str(stepnumber)endif(freezel)run=0;freeze=0;enddrawnow%needthisintheloopforcontrolstoworkendExamples1. ConwaySlife.Theruleis:oSumthe8nearestneighborsoIfthesum=2thenthestatedoesnotchangeoIfthesum=3thenth

9、estate=loOtherwisethestate=OThecode:x=2:n-l;y-2:n-l;%nearestneighborsumsum(x,y)=cells(x,y-l)+cells(x,y+l)+.cells(x-l,y)+cells(x+l,y)+.cells(x-l,y-l)+cells(x-l,y+l)+.cells(3:n,y-l)+cells(x+l,y+l);%TheCArulecells=(sum=3)I(sum=2&cells);2. SUrfaCeTenSionTheruleis:oSumthe8nearestneighborsandthecellitself

10、oIfthesum4orsum=5thenthestate=OoOtherwisethestate-1Thecode:x=2:n-l;y=2:n-l;sum(x,y)=cells(x,y-l)+cells(x,y+l)+.cells(-l,y)+cells(x+l,y)+.cells(-l,y-l)+cells(-l,y+l)+cells(3:n,y-l)+cells(xl,y+l)+.cells(x,y);%TheCArulecells=(sum0(atleastoneneighbor)andtherthreshold,andthecellhasneverhadaneighborthence

11、ll=l.oIfthesum0setthevisitedflagforthecel1torecordthatthecellhasanonzeroneighbor.Theupdatecode:sum(2:a-l,2:b-l)=cells(2:a-l,1:b-2)+cells(2:a-l,3:b)+.cells(1:a-2,2:bT)+cells(3:a,2:b-l)+cells(1:a-2,1:b-2)+cells(1:a-2,3:b)+cells(3:a,1:b-2)+cells(3:a,3:b);pick=rand(a,b);cells=cells(sum=l)&(pick=threshol

12、d)&(visit=0)visit-(sum=l);Thevariablesaandbarethesizeoftheimage.Theinitalimageisdeterminedbygraphicsoperations.Thefollowingstatementssetupaxesofafixedsize,writetextintotheaxes,thengrabthecontentsoftheaxesandputthembackintoanarrayusingthegetframefunction.ax-axes(,units,pixels,position,11500400,color,

13、k,);text(,units,pixels,position,50,255,0,string,BioNB,color,w,fontname,helvetica,fontsize,100)text(,units,pixels,position,120,120,0,.,string,44,color,w,fontname,helvetica,fontsize,100)initial-getframe(gca);a,b,c-size(initial.cdata);z=zeros(a,b);cells=double(initial,cdata(:,:,1)255);visit=Z;sum=z;Aft

14、erafewdozentimesteps(startingwiththeBioNB441image)wegetthefollowingimage.Clickonittoseeafullsizeimage.4. EXCitabIeInedia(BZreactionorheart)Therule:oCellscanbein10differentstates.State0isresting.States1-5areactive,andstates6-9arerefractory.oCountthe8nearestneighborsofeachcellwhichareinoneoftheactivestates.oIfthesumisgreaterorequalto3(atleastthreeactiveneighbors)thencell=l.oStates1to9occurstepwisewithnomoreinput.I

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 并行计算/云计算

copyright@ 2008-2023 yzwku网站版权所有

经营许可证编号:宁ICP备2022001189号-2

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!