Question: Write a script named YourLastNameA6_HW_1.m Pattern Finding Problem Given a vector of arbitrary length consisting of ones and zeros, and a pattern such as

Write a script named "YourLastNameA6_HW_1.m" Pattern Finding Problem Given a vector of arbitrary length  

Write a script named "YourLastNameA6_HW_1.m" Pattern Finding Problem Given a vector of arbitrary length consisting of ones and zeros, and a pattern such as [1 0 1 0], your goal is to determine if the pattern occurs in the vector and the starting index of its location. 1. Write a local function GenVector that takes as its input argument the length of the vector and returns a random vector of that length consisting of random Os and 1s. Name this random vector rVec. 2. Write a local function ContainsMatch that takes two input arguments, the random vector rVec and the pattern to test testPatt. The function should return either false (logical 0) if the pattern is not found, or the index of the starting position of the first occurrence of the test pattern in the test vector. For example, suppose rVec = [101011] and testPatt = [1 1] your function should return: 5, since [11] starts at index position 5. 3. You should test with special cases (are the inputs Os and 1s? is the length of testPatt less than or equal to the length of rVec? Anything else you can think of?) 4. Clearly document your code. Make your sample vector length equal to 100. Some sample patterns to test: testPat1 = [1] testPat2 = [1010] test Pat3 = [0 0 0 0] test Pat4 = [00001111] i. ii. iv.

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution YourLastNameA6HW1m Local function GenVector generates a random vector of ones and zeros ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!