Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab Question Each part references the previous question which is below. (I answered all of these) Here are my answers for the previous question, which

Matlab Question

image text in transcribed

Each part references the previous question which is below. (I answered all of these)

image text in transcribed

Here are my answers for the previous question, which will help with problem 2.

image text in transcribed

Please answer question #2 parts a through d
2. a. Redor For this question, re-do some parts of Problem 1 without using the functions above, as described below: Redo part (a) using indexing and assignment instead of the strrep function. Your code does not have to be flexible; that is, it only needs to work on fair. Store the resulting variable as fair2a, which should be identical to fair2 (1.5 points). DO NOT USE THE sttrep FUNCTION. Redo part (c) by converting a copy of fairy to a character vector, extracting each word as a separate variable using indexing, converting each word to a string, and concatenating them into a vector called fair4b, which should be identical to fair4 (1.5 points). Your code does not need to "find" the spaces, instead, you can find them some other way (e.g., visual examination) and hard-code the locations of the words into your script. DO NOT USE THE split FUNCTION. Redo part (d) by creating a copy of fair4 called fair5c, then writing a loop that reverses each element of fair5c (1.5 points). The resulting vector fair5c should be identical to fair5. I solved this by, at each iteration, converting the word to a character vector, then reversing its elements (fliplr function), then saving the result back into fair5c as a string. DO NOT USE THE reverse FUNCTION Redo part (e) by making a copy of fair5, converting each string to a character vector (using separate variables if necessary), concatenating them (with spaces in between), then converting back to string. Store the result as fair6d, which should be identical to fair6 (1.5 points). DO NOT USE THE strjoin FUNCTION Use the following command to create a character vector called fair (1 point): fair= 'The rain in Spain stays mainly in the plain.' Remember to be careful when copying over single quotes into MATLAB; you may have to replace them with single quotes within MATLAB to avoid errors. NOTE: For full credit, the variable fair should be in your workspace when your code finishes, unchanged from when it was defined here. los a Each of the following problems requires the use of a MATLAB function which was not discussed in lecture. This is intended, and these functions are not overly complicated. Use the help or doc functions, plus Google if you need to, to use these functions to perform the corresponding tasks. NOTE: Throughout this process, treat the capital T and S and the period the same as any other letter. This is the default behavior for all of these functions; don't do anything extra for them. Use the strrep function to replace all instances of 'ai' and 'ay' in fair with 'eye'. Store the resulting character vector as fair2 (.5 points) b. Use the string function to convert fair2 into a 1 by 1 string array. Store this string array as fair3 (.5 points) Use the split function to split fair3 at the spaces, such that the resulting string array has 9 elements, each of which is one of the words in fair3, and no spaces. The period at the end should be treated the same as the other letters. Store this string array as fair4. (.5 points) Create a copy of fair4 called fair5. Use the reverse function to reverse the order of the letters in each word of fair5, storing the result as fair5 (.5 points) Use the strjoin function to combine the elements of fair5 into a single string, using a space' 'to separate each pair of words. The resulting string should contain the words in fair5 with a space between each word. Store the result as fair6 (.5 points) Finally, use the char function to convert fair6 to a character vector. Store the resulting character vector as fair7. (.5 points) %problem 1 fair = 'The rain in Spain stays mainly in the plain.' %problem la fair2 = strrep(fair,'ai', 'eye'); fair2 = strrep(fair2, 'ay', 'eye') %problem 1b fair3 = string(fair2) %problem 1c fair4 = split(fair3) %problem 1d fair5 = fair4; fair5 = reverse (fair5) %problem le fair6 = strjoin(fair5, ''). %problem if fair7 = char(fair6) 2. a. Redor For this question, re-do some parts of Problem 1 without using the functions above, as described below: Redo part (a) using indexing and assignment instead of the strrep function. Your code does not have to be flexible; that is, it only needs to work on fair. Store the resulting variable as fair2a, which should be identical to fair2 (1.5 points). DO NOT USE THE sttrep FUNCTION. Redo part (c) by converting a copy of fairy to a character vector, extracting each word as a separate variable using indexing, converting each word to a string, and concatenating them into a vector called fair4b, which should be identical to fair4 (1.5 points). Your code does not need to "find" the spaces, instead, you can find them some other way (e.g., visual examination) and hard-code the locations of the words into your script. DO NOT USE THE split FUNCTION. Redo part (d) by creating a copy of fair4 called fair5c, then writing a loop that reverses each element of fair5c (1.5 points). The resulting vector fair5c should be identical to fair5. I solved this by, at each iteration, converting the word to a character vector, then reversing its elements (fliplr function), then saving the result back into fair5c as a string. DO NOT USE THE reverse FUNCTION Redo part (e) by making a copy of fair5, converting each string to a character vector (using separate variables if necessary), concatenating them (with spaces in between), then converting back to string. Store the result as fair6d, which should be identical to fair6 (1.5 points). DO NOT USE THE strjoin FUNCTION Use the following command to create a character vector called fair (1 point): fair= 'The rain in Spain stays mainly in the plain.' Remember to be careful when copying over single quotes into MATLAB; you may have to replace them with single quotes within MATLAB to avoid errors. NOTE: For full credit, the variable fair should be in your workspace when your code finishes, unchanged from when it was defined here. los a Each of the following problems requires the use of a MATLAB function which was not discussed in lecture. This is intended, and these functions are not overly complicated. Use the help or doc functions, plus Google if you need to, to use these functions to perform the corresponding tasks. NOTE: Throughout this process, treat the capital T and S and the period the same as any other letter. This is the default behavior for all of these functions; don't do anything extra for them. Use the strrep function to replace all instances of 'ai' and 'ay' in fair with 'eye'. Store the resulting character vector as fair2 (.5 points) b. Use the string function to convert fair2 into a 1 by 1 string array. Store this string array as fair3 (.5 points) Use the split function to split fair3 at the spaces, such that the resulting string array has 9 elements, each of which is one of the words in fair3, and no spaces. The period at the end should be treated the same as the other letters. Store this string array as fair4. (.5 points) Create a copy of fair4 called fair5. Use the reverse function to reverse the order of the letters in each word of fair5, storing the result as fair5 (.5 points) Use the strjoin function to combine the elements of fair5 into a single string, using a space' 'to separate each pair of words. The resulting string should contain the words in fair5 with a space between each word. Store the result as fair6 (.5 points) Finally, use the char function to convert fair6 to a character vector. Store the resulting character vector as fair7. (.5 points) %problem 1 fair = 'The rain in Spain stays mainly in the plain.' %problem la fair2 = strrep(fair,'ai', 'eye'); fair2 = strrep(fair2, 'ay', 'eye') %problem 1b fair3 = string(fair2) %problem 1c fair4 = split(fair3) %problem 1d fair5 = fair4; fair5 = reverse (fair5) %problem le fair6 = strjoin(fair5, ''). %problem if fair7 = char(fair6)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago