• 大小: 90KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: Matlab
  • 标签: matlab  

资源简介

基于元胞自动机的Matlab仿真程序,都可以运行,还不错哦!拿来和大家分享!

资源截图

代码片段和文件信息


%Conway‘s life with GUI

clf
clear all

%=============================================
%build the GUI
%define the plot button
plotbutton=uicontrol(‘style‘‘pushbutton‘...
   ‘string‘‘Run‘ ...
   ‘fontsize‘12 ...
   ‘position‘[1004005020] ...
   ‘callback‘ ‘run=1;‘);

%define the stop button
erasebutton=uicontrol(‘style‘‘pushbutton‘...
   ‘string‘‘Stop‘ ...
   ‘fontsize‘12 ...
   ‘position‘[2004005020] ...
   ‘callback‘‘freeze=1;‘);

%define the Quit button
quitbutton=uicontrol(‘style‘‘pushbutton‘...
   ‘string‘‘Quit‘ ...
   ‘fontsize‘12 ...
   ‘position‘[3004005020] ...
   ‘callback‘‘stop=1;close;‘);

number = uicontrol(‘style‘‘text‘ ...
    ‘string‘‘1‘ ...
   ‘fontsize‘12 ...
   ‘position‘[204005020]);
    

%=============================================
%CA setup

n=128;

%initialize the arrays
z = zeros(nn);
cells = z;
sum = z;
%set a few cells to one
cells(n/2.25*n:.75*n) = 1;
cells(.25*n:.75*nn/2) = 1;

%cells(.5*n-1.5*n-1)=1;
%cells(.5*n-2.5*n-2)=1;
%cells(.5*n-3.5*n-3)=1;
cells = (rand(nn))<.5 ;
%how long for each case to stability or simple oscillators

%build an image and display it
imh = image(cat(3cellszz));
set(imh ‘erasemode‘ ‘none‘)
axis equal
axis tight

%index definition for cell update
x = 2:n-1;
y = 2:n-1;

%Main event loop
stop= 0; %wait for a quit button push
run = 0; %wait for a draw 
freeze = 0; %wait for a freeze

while (stop==0) 
    
    if (run==1)
        %nearest neighbor sum
        sum(xy) = cells(xy-1) + cells(xy+1) + ...
            cells(x-1 y) + cells(x+1y) + ...
            cells(x-1y-1) + cells(x-1y+1) + ...
            cells(3:ny-1) + cells(x+1y+1);
        % The CA rule
        cells = (sum==3) | (sum==2 & cells);       
        %draw the new image
        set(imh ‘cdata‘ cat(3cellszz) )
        %update the step number diaplay
        stepnumber = 1 + str2num(get(number‘string‘));
        set(number‘string‘num2str(stepnumber))
    end
    
    if (freeze==1)
        run = 0;
        freeze = 0;
    end
    
    drawnow  %need this in the loop for controls to work
    
end
    
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2010-09-09 20:09  CA+matlab\CA matlab\
     目录           0  2010-09-09 20:09  CA+matlab\CA matlab\CA.files\
     文件        3101  2006-05-15 10:47  CA+matlab\CA matlab\CA.files\Diffusion1.gif
     文件       25386  2006-05-15 10:47  CA+matlab\CA matlab\CA.files\excitable1.png
     文件       35874  2006-05-15 10:47  CA+matlab\CA matlab\CA.files\percolationSmall.png
     文件       19456  2010-03-14 09:50  CA+matlab\CA matlab\CA.files\Thumbs.db
     文件       29081  2006-05-15 10:50  CA+matlab\CA matlab\CA.htm
     文件        2226  2006-05-15 10:50  CA+matlab\CA matlab\calife.m
     文件        2248  2006-05-15 10:50  CA+matlab\CA matlab\CAsurfaceT.m
     文件        1210  2006-05-15 10:50  CA+matlab\CA matlab\CAvine.m
     文件        1789  2006-05-15 10:49  CA+matlab\CA matlab\diffusion.m
     文件        1208  2006-05-15 10:49  CA+matlab\CA matlab\excitable.m
     文件         803  2006-05-15 10:49  CA+matlab\CA matlab\forest.m
     文件        3196  2006-05-15 10:49  CA+matlab\CA matlab\gas2.m
     文件        2153  2006-05-15 10:49  CA+matlab\CA matlab\sand.m

评论

共有 条评论