Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
having problems with simulating game of life in matlab

Subject: having problems with simulating game of life in matlab

From: Christian

Date: 17 Dec, 2010 17:54:05

Message: 1 of 2

following function isn't working..the population is dying away without recouperating. I am supposed to deal with the edges as well. Please help me for the correct algorithm.

unction [] =gameoflife(e)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
a= zeros(e);
b= zeros(e);
dad=e;
bad=e;
bad=bad-1;
for i=1:e
    for k=1:e
      xx=rand(1);
        if(xx<0.5)
         xx=0;
        else xx=1;
            
        end
    a(i,k)=xx ;
    end
end

 

for l=1:10;
for i=2:bad
    for k=2:bad
        x0=a(i,k);
        x1=a((i-1),(k-1));
        x2=a(i,(k-1));
        x3=a((i+1),(k-1));
        x4=a((i-1),k);
        x5=a((i+1),k);
        x6=a((i-1),(k+1));
        x7=a(i,(k+1));
        x8=a((i+1),(k+1));

        


         dadd=(x1+x2+x3+x4+x5+x6+x7+x8);
   
        if (x0==0)&&(dadd==3)
            b(i,k)=1;
           end
        if (x0==1)&&(dadd>=4)
            b(i,k)=0;
        end
        if(x0==1)&&(dadd==2)
            b(i,k)=1;
        end
        if (x0==1)&&(dadd==3)
           b(i,k)=1;
        end
      if (x0==0)&&(dadd==2)
            b(i,k)=0;
        end
        if(x0==0)&&(dadd==3)
            b(i,k)=0;
        end
 
          if (x0==1) && (dadd<=1)
            b(i,k)=0;
          end

          
          end
    end

    imagesc(b)
 
    pause (0.5);
    a=b;
  
end
end

Subject: having problems with simulating game of life in matlab

From: Sean de

Date: 17 Dec, 2010 18:09:05

Message: 2 of 2

"Christian " <chris.outwright@googlemail.com> wrote in message
> for i=1:e
> for k=1:e
> xx=rand(1);
> if(xx<0.5)
> xx=0;
> else xx=1;
>
> end
> a(i,k)=xx ;
> end
> end
>

One step:
replace the above with:
a = rand(e)>=0.5;

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us