Question
MATLAB HELP!!!! Write a script called lastnameConway.m with the following elements: 1. Use the readpattern() function (provided below) to read any one of five pattern
MATLAB HELP!!!!
Write a script called lastnameConway.m with the following elements:
1. Use the readpattern() function (provided below) to read any one of five pattern files (also provided below) as a variable called P.
2. Determine the width (W) and height (H) of P.
3. Create board (B) of all zeros whose width is 4*W and height is 4*H.
4. Place the pattern P near the center of board B.
5. Apply the rules of Conway's Game of Life using the functions and procedures we described in lecture to animate 100 generations with a delay of 0.25 s between animation updates.
Code for readpattern:
function P = readpattern(filename) % Example usage: % % P = readpattern('galaxy.txt'); % % S = readlines(filename); nRow = length(S); nCol = strlength(S(1)); P = zeros(nRow, nCol); for i = 1:nRow thisRow = char(S(i)); for j = 1:nCol thisChar = thisRow(j); if strcmp(thisChar, 'O') P(i,j) = 1; end end end
Pattern File:
..O..O.O. OO.O.OOO. .O......O OO.....O. ......... .O.....OO O......O. .OOO.O.OO .O.O..O..
Step 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