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

📄 runeco1.m

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

% load fundamental paramters
% See detail in SETECO.m
load c:\ecody\stepfp
nl=nls(1);
cp=zeros(tmax(1)+1,ns(1)-1);

% load Rule
load c:\ecody\rule1

% Set the initial state
X = zeros(nl,tmax(1));

if pd0(dos)==0 
	p0=1;
else 
	p0=fix(pd0(dos)*nl*itr(dos)); % Initial population
end
ita=fix(nl*itr(1)); % Initial thriving range

i=1;
if rg(1) rand('state',0); end
while i<=p0
	randx=fix(ita*rand)+1+fix((nl-ita)/2);
	if X(randx,1)==0
		X(randx,1)=X(randx,1)+ceil(rand*(ns(1)-1));
		i=i+1;
	end		
end

% Set up the graphic envirnment
fig=figure(1);
clf;
axes('position',[0.13 0.11 0.675 0.815]);
msize=max(2,fix(1/max(tmax(1),nl)*1500));

% The following statements plot the initial configuration.
gra=1; %Graph is visible
if ns(1)==2
	[x1,y1]=find(X);
	plothandle=plot(x1,y1,'.','markersize',msize,'erasemode','none');
else
	[x1,y1]=find( (X-2) & X);
	[x2,y2]=find(X>1);
	plothandle=plot(x1,y1,'.',x2,y2,'.','markersize',msize,'erasemode','none');
end
axis([0 nl+1 0 tmax(1)+1]);

% The progress of the simulation is controlled by t and tfinal.
% Initially,

tfinal = 0;
t = 0;
timehandle=title(num2str(t));
for i=1:ns(1)-1
	cp(1,i)=sum(~(X(:,1)-i));
end

%AUTO FUNCTION
if (exist('auto') & auto==1)
	tfinal=tmax(dos);
	ecoloop1;
	dispop;
	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 "Done" to make tfinal negative and clear the figure.
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'');');
% Run single step
stephandle = uicontrol('position',[480 340 50 25],'string','step', ...
    'callback',['tfinal=t+1; ecoloop1;']);
% Run until STOP button or tmax
gohandle = uicontrol('position',[480 300 50 25],'string','go', ...
    'callback',['if finite(tfinal) tfinal=tmax(dos); ecoloop1; end'], ...
    'interruptible','on');
% Stop the RUN
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 -noui;']);
% Dump graph
donehandle = uicontrol('position',[480 100 50 25],'string','dump', ...
     'callback',['dump=[x1 y1]; save c:\ecody\dump.dat dump -ascii -tabs; clear dump;']);
% Close the window
%donehandle = uicontrol('position',[480 60 50 25],'string','close', ...
%    'callback',['tfinal = -1; clf']);

end

⌨️ 快捷键说明

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