Question: For MATLAB programming: Put all answers in a MATLAB script named file7.m. Make sure that figure 1 is plotted when script is executed. Use double

For MATLAB programming: Put all answers in a MATLAB script named file7.m. Make sure that figure 1 is plotted when script is executed. Use double precision unless otherwise stated. stringA.mat: (1x1784 matrix) This chapter will cover statements in MATLAB that allow other statement(s) to be repeated. The statements that do this are called looping statements or loops. There are two basic kinds of loops in programming: counted loops and conditional loops. A counted loop is a loop that repeats statements a specified number of times (so, ahead of time it is known how many times the statements are to be repeated). In a counted loop, for example, you might say 'repeat these statements 10 times'. A conditional loop also repeats statements, but ahead of time it is not known how many times the statements will need to be repeated. With a conditional loop, for example, you might say 'repeat these statements until this condition becomes false'. The statement(s) that are repeated in any loop are called the action of the loop. There are two different loop statements in MATLAB: the for statement and the while statement. In practice, the for statement is used as the counted loop, and the while is usually used as the conditional loop. To keep it simple, that is how they will be presented here. In many programming languages, looping through the elements in a vector or matrix is a very fundamental concept. In MATLAB, however, as it is written to work with vectors and matrices, looping through elements is usually not necessary. Instead, 'vectorized code' is used, which means replacing the loops through matrices with the use of built-in functions and operators. Both methods will be described in this chapter. The earlier sections will focus on 'the programming concepts', using loops. These will be contrasted with 'the efficient methods', using vectorized code. Loops are still relevant and necessary in MATLAB in other contexts, just not normally when working with vectors or matrices. MATLAB character datatype stores a string as a vector of characters. For example, if stringA = 'Test', then stringA(1) = 'T', stringA(end) = 't' and length(stringA) = 4. I n this exercise, you will use for loops and switch statements to examine a string. Use the file stringA.mat and load it into MATLAB. (a - c) How many times do the substrings 'how', 'are', and 'for' appear in stringA? Put the answers into 1a, 1b, and 1c, respectively. (d - f) How many times do the substrings 'many', 'time', and 'loop' appear in stringA? Put the answers into p1d, p1e, and p1f, respectively.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!