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
阿里matlab建模师
- 粉丝: 4278
- 资源: 2844
最新资源
- 基于Eclipse Paho Mqtt 的简单封装详细文档+全部资料.zip
- 基于electron-vue,mqtt,借鉴微信体验,支持windows,linux,mac三大平台详细文档+全部资料.zip
- 基于DuerOS的对话式物联网控制示例,采用了百度的物联网IoT Hub MQTT Server详细文档+全部资料.zip
- 基于esp8266 mqtt arduino IDE开发的系列IOT引用项目详细文档+全部资料.zip
- 基于ESP利用MQTT通信、IRext开源库实现万能红外遥控详细文档+全部资料.zip
- 基于golang和gin框架一个快速接入MQTT物联网设备的服务器详细文档+全部资料.zip
- 基于esp32-wifi实现mqtt手持测量仪详细文档+全部资料.zip
- 基于Flask框架使用MQTT进行消息互动详细文档+全部资料.zip
- 基于hyperf建立的mqtt服务端详细文档+全部资料.zip
- 基于Go语言的SiteWhere(物联网平台)服务搭建【+SDK ( JSON、REST、MQTT 通信 ) 】详细文档+全部资料.zip
- 基于Go语言实现:基于Eclipse Paho MQTT Go client、GIN框架实现ThingsBoard提供的MQTT、HTTP API详细文档+全部资料.zip
- 基于linux平台C++编写的高性能异步mqtt协议代理服务详细文档+全部资料.zip
- 基于Kotlin Multiplatform的跨平台socket通信统一接口,在对Kotlin有较好的支持的同时兼容在JAVA中调用。目前支持Android目标
- 基于mqtt.js针对egg封装的插件,可以在agent进程上稳定运行,开箱即用详细文档+全部资料.zip
- 基于Lora的物联网监管系统服务器, SSM+MySQL+MQTT详细文档+全部资料.zip
- 基于micropython可以触控和MQTT控制的按钮开关详细文档+全部资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈