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

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 )

Background:

Its Valentines Day in elementary school, and you just got home with your prettily-crafted

shoebox thats stuffed to the brim with candies from your friends and classmates. As you dump

out the contents of your makeshift mailbox, you stumble across a box of your favorite festive

candy: Sweethearts! Eager to see what messages are printed on the cute little treats, you rip

open the box and pour out all of the Sweethearts onto your wooden floor, but you realize a

second too late that you were too rough with the candies when they break into smithereens

upon hitting the floor! You pick up a few pieces and attempt to put them back together, but no

matter how hard you try, you just cant find a perfect match between any of the pieces that

makes grammatical sense. Disheartened by this catastrophe, you turn to your trusty and loyal

valentine, MATLAB, to piece together the mystery of what messages were written on the

Sweethearts.

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 f ull 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 '

Homework 04 - 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.

Please solve (using MATLAB) and masking techniques. To receive a thumbs up please do not use conditional statments(if, else, elseif) or iterations(for,while) to solve this problem!!!! This is all the information given to me. AGAIN DO NOT USE( IF STATEMENTS )OR ANY OTHER CONDITIONAL STATEMENT TO SOLVE THIS PROBLEM I WILL NOT UP VOTE!!

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!