clear
clc
close all
iterations = 100;
beta = 0.95; %value for background level
gamma = 0.0035; %constant added to receptive sites
crystal_size = 101; %number of hex on top of center (note only use odd numbers)
tic %just time stuff
A = beta * ones(crystal_size*2 +1, crystal_size*2 + 1 ); %Array to store states
A(crystal_size+1, crystal_size+1) = 1; %setting the center to ice
x = -crystal_size:1:crystal_size; %array to store x positions of hexagons
y = crystal_size:-1:-crystal_size; %array to store y positions of hexagons
[X, Y] = meshgrid(x,y);
%add offset to alternate rows and columns
for i = 1:2:crystal_size*2 +1
X(i,:) = X(i,:) + 0.5;
end
Dis = sqrt(X.^2 + Y.^2);
% drawing(A,X,Y,Dis,crystal_size);
% drawnow
for i = 1 : iterations
[odd_row, even_row] = neighbor_array(A, beta);
receptive_odd = sum((odd_row >= 1) , 3)>0;
receptive_even = sum((even_row >= 1) , 3)>0;
receptive_logic = zeros(size(A));
for k = 1:size(A,1)
if mod(k,2) == 0
receptive_logic(k,:) = receptive_even(k,:);
else
receptive_logic(k,:) = receptive_odd(k,:);
end
end
unreceptive_logic = receptive_logic==0;
receptive = receptive_logic .* A;
unreceptive = unreceptive_logic .* A;
receptive_update = (receptive_logic * gamma) + receptive;
[odd_row, even_row] = neighbor_array(unreceptive, beta);
unreceptive_ne = zeros(size(odd_row));
for k = 1:size(A,1)
if mod(k,2) == 0
unreceptive_ne(k,:,:) = even_row(k,:,:);
else
unreceptive_ne(k,:,:) = odd_row(k,:,:);
end
end
averaged_neighbors = (unreceptive_ne(:,:,1)*0.5) + (unreceptive_ne(:,:,2)*(1/12)) + (unreceptive_ne(:,:,3)*(1/12)) ...
+ (unreceptive_ne(:,:,4)*(1/12)) + (unreceptive_ne(:,:,5)*(1/12)) + (unreceptive_ne(:,:,6)*(1/12)) + (unreceptive_ne(:,:,7)*(1/12));
final_update = averaged_neighbors + receptive_update;
% if mod(i,10)==0
% clf
% drawing(final_update,beta)
% drawnow
% end
clf
drawing(final_update,beta)
drawnow
A = final_update;
end
toc
tic
clf
drawing(A,beta)
drawnow
toc
没有合适的资源?快使用搜索试试~ 我知道了~
基于元胞自动机模拟晶体生成附matlab代码
共7个文件
m:5个
png:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 9 下载量 31 浏览量
2022-07-05
23:47:58
上传
评论 14
收藏 175KB ZIP 举报
温馨提示
1.版本:matlab2019a,不会运行可私信 2.领域:【元胞自动机】 3.内容:基于元胞自动机模拟晶体生成附matlab代码 4.适合人群:本科,硕士等教研学习使用
资源推荐
资源详情
资源评论
收起资源包目录
【元胞自动机】基于元胞自动机模拟晶体生成附matlab代码 上传.zip (7个子文件)
hexagon.m 213B
1.png 93KB
neighbor_array.m 943B
2.png 95KB
v_2.m 2KB
drawing.m 753B
v_1.m 2KB
共 7 条
- 1
天天Matlab科研工作室
- 粉丝: 2w+
- 资源: 7253
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页