calcmu2.m

来自「一个利用元胞自动机进行生态仿真的matlab程序」· M 代码 · 共 72 行

M
72
字号
function mu=calcmu2(code,type,lnei)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CALCMU2
% Calculate and display mu-parameter of 2-dimensional CAs
%
% called by RULEGEN2
%
%	Fist Coded			22  April  1998
%	Last Modefied		3   June  1998
%
%	Copyright (c)
%	T. Suzudo JAERI-CAIL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Argument
% type	: rule type 1:totalistic 2:outer-totalistic 3:symmetry
% code	: rule code
% lnei	: neighbor

mu=0;		% mu-parameter
nrule=2^lnei;% total number of rules
%% Totalistic
%%
if type==1
	if lnei==5
		error('ERROR : Function is not ready for the given arguments');
	elseif lnei==9
		error('ERROR : Function is not ready for the given arguments');
	else
		error('ERROR : Invalid number of neighbors');	
	end
%% Outer-totalistic
%%
elseif type==2
	if lnei==5
		if code(1)==1 mu=mu+1/nrule; end
		if code(2)==1 mu=mu+4/nrule; end
		if code(3)==1 mu=mu+6/nrule; end
		if code(4)==1 mu=mu+4/nrule; end
		if code(5)==1 mu=mu+1/nrule; end
		if code(6)==0 mu=mu+1/nrule; end
		if code(7)==0 mu=mu+4/nrule; end
		if code(8)==0 mu=mu+6/nrule; end
		if code(9)==0 mu=mu+4/nrule; end
		if code(10)==0 mu=mu+1/nrule; end
	elseif lnei==9
		error('ERROR : Function is not ready for the given arguments');
	else
		error('ERROR : Invalid number of neighbors');	
	end
%% Symmetry
%%
elseif type==3
	if lnei==5
		if code(1)==1 mu=mu+1/nrule; end
		if code(2)==1 mu=mu+4/nrule; end
		if code(3)==1 mu=mu+4/nrule; end
		if code(4)==1 mu=mu+2/nrule; end
		if code(5)==1 mu=mu+4/nrule; end
		if code(6)==1 mu=mu+1/nrule; end

		if code(7)==0 mu=mu+1/nrule; end
		if code(8)==0 mu=mu+4/nrule; end
		if code(9)==0 mu=mu+4/nrule; end
		if code(10)==0 mu=mu+2/nrule; end
		if code(11)==0 mu=mu+4/nrule; end
		if code(12)==0 mu=mu+1/nrule; end
	else
		error('ERROR : Invalid number of neighbors');	
	end
else
	error('ERROR : No such rule type');	
end

⌨️ 快捷键说明

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