⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runeco2.m

📁 一个利用元胞自动机进行生态仿真的matlab程序
💻 M
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RUNECO2: Execute 2-dimensional CA
%
%	Fist Coded		27 February 1997
%	Last Modefied	3  June   1997
%
%	Copyright (c)
%	T. Suzudo JAERI-CAIL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dos=2;
% functional parameters
% 	i:	Loop index 
%   	rg:		Switch for produce always same random number
%  	pd0:		Initial population density
%	p0:		Initial population
%	itr:		Initial thriving range


% load fundamental paramters
% See detail in SETECO.m
load c:\ecody\stepfp
cp=zeros(tmax(dos)+1,1);
nl=nls(dos);
anl = nl*nl;   % number of lattice cites
lnei=nei(dos);
lns= ns(dos); % states per cell

% Load rules
load c:\ecody\rule2

% Initial state
X = zeros(nl,nl);

if pd0(dos)==0 
	p0=1;
else 
	p0=fix(pd0(dos)*anl*itr(dos)^2); % Initial population
end
ita=fix(nl*itr(2));
i=1;
if rg(2) rand('state',0); end
while i<=p0
	randx=fix(ita*rand)+1+fix((nl-ita)/2);
	randy=fix(ita*rand)+1+fix((nl-ita)/2);
	if X(randx,randy)==0
		X(randx,randy)=X(randx,randy)+1;
		i=i+1;
	end		
end

% The following statements plot the initial configuration.
% The "find" function returns the indices of the nonzero elements.


% Setup graphics
fig=figure(1);
clf;
axes('position',[0.13 0.11 0.675 0.815]);
msize=fix(1/nl*1500);

% Graph is visible
 gra =1;
[x,y] = find(X);
if ani(dos)==2
	plothandle = plot(x,y,'.','markersize',12);
end
axis([0 nl+1 0 nl+1]);

% The progress of the simulation is controlled by t and tfinal.
% Initially,
tfinal = 0;
t = 0;
timehandle = title(num2str(t));
cp(1)=sum(sum(X));

%AUTO FUNCTION
% Make procedure as you like
if (exist('auto') & auto==1)
	if ~(tot(dos)==3)  error('ERROR: Only symmetric rule'); end 
	if ~(lnei==5)  error('ERROR: Only 5-neighbour structure'); end 
	mu=calcmu2(sym_code225,tot(dos),lnei);
	for ii=1:10
		if ii==10 Y3(:,:,1)=X; end
		tfinal=200*ii;
		ecoloop2;
		hs(ii)=entspa(Y,lns);
		if ii==10
			ht=enttim(Y3(:,:,102:201),lns);
			clear Y3;
		end
	end
	auto=0;
else
	

% The variable t is incremented in the inner loop.
% The value of tfinal is changed by four pushbuttons.

% Click "Step" to set tfinal to t+1 and get one step.
% Click "Go" to set tfinal to inf and initiate an infinite loop.
% Click "Stop" to set tfinal to t and terminate the loop.
% Click "Plot" to plot the temporal change of the population..
% Click "Done" to make tfinal negative and clear the figure.

%figure(fig);
snapshot = '[x y]=find(X); set(plothandle,''xdata'',x,''ydata'',y);';
% Graphics switch
grahandle = uicontrol('Style','checkbox','position',[480 380 50 25],'string','Graph', ...
    'Value',gra,'callback','gra=get(grahandle,''Value'');');
% Step switch
stephandle = uicontrol('position',[480 340 50 25],'string','step', ...
    'callback',['tfinal = t+1; ecoloop2; ']);
% Go switch
gohandle = uicontrol('position',[480 300 50 25],'string','go', ...
    'callback',['if finite(tfinal) tfinal = tmax(2); ecoloop2; end'], ...
    'interruptible','on');
% Stop switch
stophandle = uicontrol('position',[480 260 50 25],'string','stop', ...
    'callback',['tfinal = t;']);
% Display time-series data
pophandle = uicontrol('position',[480 220 50 25],'string','analyze',...
    'callback',['dispop;']);
% Display rules
rulhandle = uicontrol('position',[480 180 50 25],'string','rule',...
    'callback',['disrule(dos,tot(dos),ns(dos),nei(dos));']);
% Print graph
printhandle = uicontrol('position',[480 140 50 25],'string','print',...
    'callback',['print -dwin -noui;']);
% Dump graph
dumphandle = uicontrol('position',[480 100 50 25],'string','dump', ...
     'callback',['dump=[x y]; save c:\ecody\dump.dat dump -ascii -tabs; clear dump;']);

end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -