Write a function callednbspflipnth that will flip every nth


You have a vector of ones and zeros.

a) Write a function called flipNth, that will flip every Nth entry of the input vector (make the entry 0 if it is 1 and make it 1 if it is 0) and return the modified vector. The function declaration line should be function [outVec] = flipNth(inVec, N)

The first input inVec is a numeric vector of ones and zeros, like V above. The second input is a scalar integer greater than or equal to 1. The output outVec should be a numeric vector of ones and zeros of the same size as inVec.
If the function flipNth is called with only one input argument, then treat the value of N as equal to 1. This is called the default value. Hence the default behavior is to flip every element of the input vector.

b) Write a function called flipNthVal with function declaration line function outVec = flipNthVal(inVec,N,value)

hat will flip every Nth instance of a specified value (0 or 1) in an input vector and return the modified vector.
The input inVec is a numeric vector of ones and zeros. The input N performs the same role as in the previous function flipNth. The input value is which value (0 or 1) to flip. For example, if the function is called with N = 4 and value = 1, the function should flip every 4th occurrence of the value 1. If, on the other hand, the function is called with N = 2 and val = 0, the function should flip every 2nd occurrence of the value 0.

The output outVec should be a numeric vector of ones and zeros of the same size as inVec. If flipNthVal is called with one argument, the default values of N and value are both 1. IfflipNthVal is called with two arguments (inVec abdN), set value to 1.

c) Write a function called findWithOverlap with function declaration linefunction [numAppear, idx] = findWithOverlap(inVec,pattern)

The input inVec is a numeric vector of ones and zeros. The input pattern should be a row vector containing only ones and zeros and whose number of elements is less than or equal to that of inVec. Your function should count how many instances of pattern occur in inVec and return this number to numAppear. Additionally, idx should be a 1-by-numAppear array that contains the starting index for each instance of the pattern. Overlap is allowed.

If pattern has a greater number of elements than inVec, then findWithOverlap should return an empty array. Otherwise the function should return a numeric scalar.

Solution Preview :

Prepared by a verified Expert
Basic Statistics: Write a function callednbspflipnth that will flip every nth
Reference No:- TGS01555924

Now Priced at $30 (50% Discount)

Recommended (92%)

Rated (4.4/5)