Question
MATLAB %problem3 disp('*****problem3*****'); %initialize grid configurations for 3 common cases tubMatrix = [zeros(1,5); 0 0 1 0 0 ; 0 1 0 1 0; 0
MATLAB
%problem3
disp('*****problem3*****');
%initialize grid configurations for 3 common cases
tubMatrix = [zeros(1,5); 0 0 1 0 0 ; 0 1 0 1 0; 0 0 1 0 0; zeros(1,5)];
blinkerMatrix = [zeros(1,5); 0 0 1 0 0 ; 0 0 1 0 0; 0 0 1 0 0; zeros(1,5)];
shipMatrix = [zeros(1,10); 0 0 1 0 0 0 0 0 0 0; 0 0 0 1 0 0 0 0 0 0; 0 1 1 1 zeros(1,6); zeros(6,10)];
for pattern = 1:3 %repeat for each of the 3 patterns
figure()
%initialize the grid matrix depending on what type of pattern is selected
%*************************************************************************************
%YOU MUST EDIT THIS PART
%Use a switch statement to choose one of these 3 patterns based on the value
%of the variable 'pattern'
%static pattern - Tub
gridMatrix = tubMatrix;
%oscillating pattern - Blinker (initially vertical)
gridMatrix = blinkerMatrix;
%spaceship pattern - Glider
gridMatrix = shipMatrix;
%SWITCH STATEMENT ENDS HERE
%************************************************************************************
%Don't edit these two lines
dispMatrix = imresize(gridMatrix,[100, 100], 'nearest');
imshow(dispMatrix)
%**************************************************************
% YOU MUST EDIT THIS PART
%Use a while loop to keep executing this block of code until one of the following two
%things happens:
% 1. No pixel changes from one step to the next [i.e. isequal(oldMatrix, gridMatrix) is true]
% 2. 30 iterations have been executed
oldMatrix = ~gridMatrix; %initialization to make sure the loop runs at least once
%don't forget to initialize your loop counter
%PUT THE WHILE STATEMENT HERE
%don't edit the lines between the arrows
%-->
oldMatrix = gridMatrix;
%call your function to update the grid
gridMatrix = LifeSimulation(oldMatrix);
%resize the image to make it more visible and display it
%wait 0.1 second between frames
dispMatrix = imresize(gridMatrix,[200, 200], 'nearest');
imshow(dispMatrix);
pause(0.1)
%
%don't forget to increment your loop counter
%WHILE LOOP ENDS HERE
%*****************************************************************
disp('Hit any key to continue')
pause()
end
1. Conway's Game of Life Read the description of Conway's Game of Life, here Write a function that takes as input a square matrix of Os and 1s and returns an updated matrix based on the rules of the game. A 0 represents a "dead" cell, and a 1 represents a "live" cell. For this assignment,it is not necessary to update the edges of the grid (first and last columns, or first and last rows) An approach to this function is as follows: a. Make copy of the input matrix b. Determine the size of the matrix using the size() or length functions. c. Execute two nested for loops to loop over all elements of the array, excluding the edges, and for each one, do the following: i. Count the number of nearest neighbors. The easiest way to do this is to sum the 3x3 submatrix centered on the current cell, then subtract the value of the cell itself. Set the corresponding value of the output matrix to either 0 or 1, based on the rules of the game ii. Campet e retrs visually that each case evolves as it is supposed to 1. Conway's Game of Life Read the description of Conway's Game of Life, here Write a function that takes as input a square matrix of Os and 1s and returns an updated matrix based on the rules of the game. A 0 represents a "dead" cell, and a 1 represents a "live" cell. For this assignment,it is not necessary to update the edges of the grid (first and last columns, or first and last rows) An approach to this function is as follows: a. Make copy of the input matrix b. Determine the size of the matrix using the size() or length functions. c. Execute two nested for loops to loop over all elements of the array, excluding the edges, and for each one, do the following: i. Count the number of nearest neighbors. The easiest way to do this is to sum the 3x3 submatrix centered on the current cell, then subtract the value of the cell itself. Set the corresponding value of the output matrix to either 0 or 1, based on the rules of the game ii. Campet e retrs visually that each case evolves as it is supposed toStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started