MATLAB: Can anyone offer a simplified method of creating Conway’s Game of life using nested for loops

MATLAB

Need help evaluating array to follow the rules of Conway's game of life. Living cell 4 or more neighbors…. I also need the program to move one generation at a time.

Best Answer

It's actually dead easy to implement in matlab, and you don't need for loops.
m = randi(2, 500) - 1;
while true %use control C to stop
imshow(m);
drawnow;
neighbours = conv2(m, [1 1 1; 1 0 1; 1 1 1], 'same');
m = double((m & neighbours == 2) | neighbours == 3);
end