How do I change it so there are multiple "starting matrices?"

1 view (last 30 days)

I have a fire percolation problem which simulates a fire spreading along a 100x100 lattice. Currently, I have it so the starting fire starts at [1,1], however I would like it so the entire bottom row of 'trees' is lit.

function [y] = Simulation_of_forest_fire(N,p)
%N=size of the square lattice. In the problem statement it is given to be
%100
figure(1);
%sets size of forest NxN
Alive = ones(N,N);
x = 1:N;
y = 1:N;
%First we set the fire at the initial t=0 seconds
Fire_Matrix = [1,1],[100,1];
[Fire_Number,~] = size(Fire_Matrix);
for i = 1:Fire_Number
    Alive(Fire_Matrix(i,1),Fire_Matrix(i,2))=2;
end
%We now go to simulating the spread of the fire
count_max = 1000; 
%This is a limit on the maximum no. of iterations.
k=0;
 while k<count_max && Fire_Number>0
    lastC = Alive;
    Fire_number_next = 0;
    fires_next =[];
         for i = 1:Fire_Number
             if Fire_Matrix(i,1)~=1
                 if Alive(Fire_Matrix(i,1)-1,Fire_Matrix(i,2))==1
                     r = rand(1);
                     if r < p
                         Fire_number_next = Fire_number_next + 1;
                         Alive(Fire_Matrix(i,1)-1,Fire_Matrix(i,2))=2;
                         fires_next(Fire_number_next,:)=[Fire_Matrix(i,1)-1,Fire_Matrix(i,2)];
                     end
                 end
             end
             if Fire_Matrix(i,1)~=N
                 if Alive(Fire_Matrix(i,1)+1,Fire_Matrix(i,2))==1
                     r = rand(1);
                     if r < p
                         Fire_number_next = Fire_number_next + 1;
                         Alive(Fire_Matrix(i,1)+1,Fire_Matrix(i,2))=2;
                         fires_next(Fire_number_next,:)=[Fire_Matrix(i,1)+1,Fire_Matrix(i,2)];
                     end
                 end
             end
             if Fire_Matrix(i,2)~=1
                 if Alive(Fire_Matrix(i,1),Fire_Matrix(i,2)-1)==1
                     r = rand(1);
                     if r < p
                         Fire_number_next = Fire_number_next + 1;
                         Alive(Fire_Matrix(i,1),Fire_Matrix(i,2)-1)=2;
                         fires_next(Fire_number_next,:)=[Fire_Matrix(i,1),Fire_Matrix(i,2)-1];
                     end
                 end
             end
             if Fire_Matrix(i,2)~=N
                 if Alive(Fire_Matrix(i,1),Fire_Matrix(i,2)+1)==1
                     r = rand(1);
                     if r < p
                         Fire_number_next = Fire_number_next + 1;
                         Alive(Fire_Matrix(i,1),Fire_Matrix(i,2)+1)=2;
                         fires_next(Fire_number_next,:)=[Fire_Matrix(i,1),Fire_Matrix(i,2)+1];
                     end
                 end
             end
             Alive(Fire_Matrix(i,1),Fire_Matrix(i,2))=0;
         end
         surf(x,y,Alive,Alive);
         view(360,90);
         colormap([0 0 0; 1 0 0; 0 1 0])
         caxis([0 2]);
         axis([1,length(x),1,length(y),0,2])
         shading interp
         title(sprintf('Time taken in seconds = %.0f',k))
         drawnow;
         k=k+1;
         if sum(sum(abs(lastC-Alive)))==0
              break
         end
         Fire_Matrix = fires_next;
         Fire_Number = Fire_number_next;
end
     y=k;
end

Any help would be greatly appreciated. Thank you!

Answers (1)

Image Analyst
Image Analyst on 21 Dec 2017
When you say this:
%First we set the fire at the initial t=0 seconds
Fire_Matrix = [1,1],[100,1];
you're setting Fire_Matrix to a 1-by-2 array, both with values of one : [1, 1].
The [100,1] is ignored. Not sure what you wanted there.
If 1 indicated a fire, and you want a 100x100 array that is all zeros except for the last row being all 1's, then you can do
Fire_Matrix = zeros(100,100);
Fire_Matrix(end,:) = 1;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!