Cellular Automata in Matlab.docx
《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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Cellular Automata in Matlab