subject

In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0. For example, in Matlab: begin code 1 V = [1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1); end code For each of the following tasks test your code for many different values and lengths of V. (a) Write code using a for loop that will flip every third entry of Vie make the entry 0 if it is 1 or make it 1 if it is 0). This loop should modify V directly. For example V - ti, 1, 0, 1, 0, 1, 1, 0, 1) would become V = [1, 1, 1, 1, 0, 0, 1, 0, 0).
(b) Write code using a for loop that will flip every third instance of the number 1 in V. This loop should modify V directly. For example V - (1, 1, 0, 1, 0, 1, 1, 0, 1) would become V - 11, 1, 0, 0, 0, 1, 1, 0, 0).
(c) Write code using a for loop that will assign to the variable numChanges the number of times that successive elements of V change from 0 to 1 or from 1 to 0. For example if V - 10, 0, 1, 1] then numChanges would equal 1 and if V - (0, 1, 0, 1) then numChanges would equal 3
(d) Write code using a for loop that assigns to a variable nunOccurs the number of times a certain pattern, specified by the variable pattern occurs in V. For this problem, overlap is allowed, i. e. if pattern - [0, 1, 0) then the last 0 of an occurrence of [0, 1, o can be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then two instances of [0, 1, 0 should be counted and numOccurs should equal 2.
(e) Write code using a while loop that will assign to the variable numDccuraSep the number of times a certain pattern of O's and 1's occurs separately in V. The variable pattern gives 3 of 4 the certain pattern to look for. For this problem overlap is not allowed, ie if pattern - [0, 1, 0] then the last 0 of an occurrence of 10, 1. O cannot be the first 0 of the next occurrence. For example, if V = [0, 1, 0, 1, 0) then only one instance of [0, 1, 0 should be counted and numOccursSep should equal 1.
(f) Write code using a while loop that will replace a sequence, specified by the variable seqremove, with a sequencespecified by the variable seqNew seqRemove and seqNew are the same size. For this problem once a sequence is replaced, only elements following the replaced sequence should be considered. For example if seqRemove - [0, 0], seqNew - [1, 0] and V - (1, 0, 0, 0, 1), then V should become [1, 1.0, 0, 1) and not [1, 1, 1,0, 11

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 15:00
1. what are the biggest risks when using the public internet as a wide area network (wan) or transport for remote access to your organization’s it infrastructure?
Answers: 2
question
Computers and Technology, 22.06.2019 11:10
Look at the far left lane in the picture. explain what the red car is doing and what it needs to do to travel safely.
Answers: 2
question
Computers and Technology, 22.06.2019 12:40
The most complicated four letter word
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
You have read about the beginnings of the internet and how it was created. what was the internet originally created to do? (select all that apply) share research. play games. communicate. share documents. sell toys
Answers: 1
You know the right answer?
In this problem you will perform various tasks on a 1-by-n array V, whose elements are either 1 or 0...
Questions
question
Chemistry, 16.07.2019 23:30
Questions on the website: 13722363