Need help with Game of life

1 view (last 30 days)
Daniel Hodgson
Daniel Hodgson on 27 Aug 2020
Answered: Vimal Rathod on 31 Aug 2020
%I have school project which requires to programme Game of life. What im looking for is tips and trick to how to imporve my current code, im quite new to matlab and this is only the begining of my project but im getting stuck at some place and would really appriciate some help. I have tried to be as clear as possible.
clc, clear all
%figure below is mandatory starting condition
b=zeros(16) ;%matrix all zeros
b(5:9,5)=1 ;% left ones
b(7:11,11)=1 ;%right ones
b(5,7:11)=1 ;%top ones
b(11,5:9)=1; %bottom ones
spy(b,40,'g'); % plot picture
[y,x]=find(a)%helps find all ones in matrix
for i=1:length(x) %trying to calcule neighbours around each cell containing one
%adds up all neighbour cell
%WANT TO DO: plug c values into vector then change vector(vales) with conditions below
%then plug back into matrix a replacing the numbers that were there before
if c<2
elseif c or(2, 3)
elseif c>3

Accepted Answer

Vimal Rathod
Vimal Rathod on 31 Aug 2020
You could use the conv2 function to find out the elements in the neighbours and then calculate the sum directly.
Below is a link for an answer which could be of use to you.
For more info about conv2 refer to the following link
hope this helps!

More Answers (0)


Find more on Conway's Game of Life in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!