function SimpleFireSpread(N,P,S)
%QQ此│707914447
%% SIMPLE FOREST FIRE SPREAD
%Function models a forest fire with each tree on fire has a set probability
%to ignite a tree which hasn't been burnt in its Moore Neighbourhood.
%The output is an animated graph showing the fire spread.
%% DEFINING INPUT
%N - The size of the matrix on which the forest will be grown (N*N)
%P - The average percantage of the matrix that will be forested (A P%
%chance for each tree to grow)
%S - The probability (as a percentage) of a fire to spread to neighbouring trees
%% INPUT ERRORS
if N < 1 || floor(N) ~= N %Invalid size
error('No valid input for size. Must be a positive integer.')
end
if P < 0 || floor(P) ~= P || P>100 %Invalid percent coverage
error('No valid input for percent coverage. Must be an integer value from 0 to 100')
end
if S < 0 || floor(S) ~= S || S>100 %Invalid spread probability
error('No valid input for spread probability. Must be an integer value from 0 to 100')
end
%% SETUP
F=Forest(N,P); %Randomly plotting a forest to burn
Spread=[0 1; 1 1; 1 0; 1 -1; 0 -1; -1 -1; -1 0; -1 1]; %Possible spreads (Moore Neighbourhood)
t=0; %Initial fire occurs at timestep 0
f=find(~F); %Finding all trees
F(f(randi(length(f))))=1; %Starting a fire on a random tree
%% LOOPS
while ~isempty(find(F==1,1)) %Loop only runs while there are fires
[i,j]=find(F==1); %Coordinates of the fire
for x=1:length(i) %For each fire
for M=1:8 %Checking each spreading option
try %Makes it so off grid checks don't cause an error
if F(i(x)+Spread(M),j(x)+Spread(M+8))==0 %Checking for trees
if randi([1,100])<= S %Chance a tree will ignite
F(i(x)+Spread(M),j(x)+Spread(M+8))=1; %Fire spreads to found trees
end
end
end
F(i(x),j(x))=2; %Trees that have been burned
end
end
imagesc(F); %The updated forest
drawnow; %Updating the plot each loop
title(['t = ' num2str(t)]) %Time since start of fire to be seen on the plot
t=t+1; %Timesteps spent burning
end
![avatar](https://profile-avatar.csdnimg.cn/2588731bac124b388c4a87fce0b1493c_m0_53407570.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
阿里matlab建模师
- 粉丝: 4938
- 资源: 2898
最新资源
- 计算机系统:虚拟内存与缓存技术解析及其应用
- Simulink仿真模型:自适应同步电机死区补偿效果展示-零点电流平滑,实测性能提升(Matlab 2018版),Matlab 2018 Simulink仿真模型中的同步电机死区补偿自适应调整:零点
- COMSOL仿真中的锂离子电池枝晶生长分析:现成模型与三种物理场综合分析,COMSOL仿真中的锂离子电池枝晶生长分析:现成模型与物理场分析,锂枝晶 仿真 comsol comsol锂枝晶模型,拿到就能
- vcds 10.63中文版
- 三相光伏并网仿真模型:Boost三相逆变器与PLL锁相环结合,实现MPPT最大功率点跟踪与dq解耦控制策略下的电流内环电压外环并网控制 ,三相光伏并网仿真模型:Boost三相逆变器与PLL锁相环结合
- 基于相场流场温度场的金属合金凝固与连铸过程数值模拟:坯壳厚度计算研究,COMSOL数值模拟在金属合金凝固与连铸过程中的应用:相场流场温度场与坯壳厚度计算分析,comsol数值模拟 金属合金凝固数值模
- vcds 12.12.2
- NCP1236中文手册
- 苹果CMS V10模板精仿BT电影天堂影视模板PC+手机
- Matlab 2017b与Maxwell Electronics 2021b下的永磁同步电机矢量控制联合仿真:分数槽绕组与SVPWM调制,基于Matlab 2017b与Maxwell Electron
- APP测试核心技术指南:从功能测试到专项测试
- MATLAB+图像检测+车牌检测+形态学运算+色彩空间转换+掩膜分割
- Multisim14共基集射源漏栅放大电路
- 帝国cms7.5内核情书网整站源码 文学类通用粉色模板同步生成带手机端数据
- 2009年上半年软件设计师上午真题-试卷和答案解析
- 苹果cmsV10仿电影先生2.0精美大气在线影视电影网站模板
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)