Question: Function Name: sweetHeart Inputs: 1. (char) A string of chars containing the first part of the broken Sweetheart message 2. (char) 1x4*N character vector of

Function Name: sweetHeart

Inputs:

1. (char) A string of chars containing the first part of the broken Sweetheart message

2. (char) 1x4*N character vector of the words Yay and Nay

3. (char) 1x4*N character vector containing potential words for the missing part of the Sweetheart message

Outputs: 1. (char) The message of the fixed Sweetheart

Topics: (strings and vectors), (masking), (concatenation)

Function Description:

Given the inputs described above, write a function that performs the following operations: First, find all positions of the word Yay in the second input. The words in the second input will always be Yay and Nay in this format. Next, using the positions found in the previous step, find the corresponding words in the third input. If Yay shows up as the second word in input 2, then the corresponding word will be the second full word in input 3 (not the second index of input 3). All words in the third input will be 3 chars long, and there will be a space after each word, including the last one. Finally, concatenate the first input with the words found in step 2 to output the full message of the fixed Sweetheart. Remember to put a space between the first input and the words found in step 2 in your final output, and make sure that the end of your fixed Sweetheart doesnt have an empty space!

Example:

brokenMessage = 'BE' str = 'Yay Nay Nay Nay Nay Nay Nay Yay '

Masking words = 'MIN HEY THE RE! HRU DOI NG? E<3

[fixedMessage] = sweetHeart(brokenMessage, str, words)

fixedMessage = BE MIN E<3

Notes: It is possible for you to have more than one instance of Yay in the second input.

Each Yay and Nay will be separated by a space, with an extra trailing space at the end of the string vector.

The second and third vectors will always be the same length.

Hints: Instead of trying to figure out how to do everything all at once, solve this problem step-by-step.

The functions zeros() and ones() may be useful in solving this problem.

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!