Question

MATLAB Function Name: vineConpilation Inputs: 1. (chan The first vine quote 2. (chan The second ine quote Outputs: 1 (chan A complilation of the vines Background: Its Sunday aftemoon and youre hanging out in your lounge, finishing of your Sprite Cranberry. Your Mom Friend (Jared, 19) walks in and yells at you for drinking soda for breakfast. Aggravated, you YEET the empty can down the hall as Jared drags you to he kitchen to make breakfast. You open the fridge to find some tortillas, eggs, and wow! Look at all hat chicken! Jared says he could make the perfect breakfast tacos if he only had some tre sha voca do. You guys get your fre sha voca dos and Jared makes you some scrumptious breaktast tacos. To repay him, you make him a compllation of his favorite vines, with a litie help from your friend MATLAB! Glven two string Inputs, swap the first and second halves of the first Input and sort the second Input in reverse alphabetical order. Then, comple the two strings by Inserting the first string Into the odd Indices of the output, and the second string Into the even Indices of the output it one string s longer than the other, add exclamation points to the end of the shorter string so the strings are the same length. Example: This can empty compilation vineCompilation(vinel, vine2) vine! pty. YEET! This can en vine2 Notes: lf the nrst strings length is an odd number, spit half being longer than the second, then swap them into two unequal halves with the first · Hints: The sort)function can take in two parameters The ceil() function may be useful.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, please find the answer below:

Code:function output vineCompilation (stringl, string2) len stringl - length (stringl) len string2length (string2): mid ceil (len string1/2); %Finding the lengths of input strings %Middle index of first string second half of inputl strl strcat (string! (mid+1:1enstring!), string! (1:mid)) string2 sort (string2, descend) %Swapping first - %sorting second string in reverse alphabetical order output_length len stringl+len string2; %Finding the largest string and appending ! to the end if (len stringl<len string2) %second string is larger diff len string2-len_stringl: for i-len_stringltl:len_stringl+diff strl (i) %appending ! to the end end disp (strl) output length-: len string2 *2; %length of output elseif (len string!>len string2) %first string is larger diff len stringl-len_string2: for i-len_string2tl:len_string2+diff string2 (i) %appending ! to the end end disp (string2) output length-: len string! *2; %length of output endindi-1; %start index for first string ind2-1; %start index for second string šCreating output Efor j1:output_length if (rem (

Output:

>> vine strl jklabcd string2 hgfe hgfe!!! op jhkglfaeb!c!d!

Firstly, the length of both the inputs is found. The first string is swapped with first and second halves. The second string is sorted in descending order of alphabets. The longer string is found and '!' symbols are added to the end of shorter strings. Finally, the output is formed by adding the first string in odd indices and second string in even indices. I have added comments for easy understanding. I have attached screenshots of the function code. Create a new file to call the function with input arguments like:

op = vineCompilation('abcdjkl','efgh')

Please find the editable code below:

function output = vineCompilation(string1,string2)
len_string1 = length(string1); %Finding the lengths of input strings
len_string2 = length(string2);
mid = ceil(len_string1/2); %Middle index of first string

str1 = strcat(string1(mid+1:len_string1),string1(1:mid)) %Swapping first and second half of input1
string2 = sort(string2,'descend') %sorting second string in reverse alphabetical order

output_length = len_string1+len_string2;
%Finding the largest string and appending ! to the end
if(len_string1<len_string2) %second string is larger
diff = len_string2-len_string1;
for i=len_string1+1:len_string1+diff
str1(i)='!'; %appending ! to the end
end
disp(str1)
output_length = len_string2 *2; %length of output
  
elseif(len_string1>len_string2) %first string is larger
diff = len_string1-len_string2;
for i=len_string2+1:len_string2+diff
string2(i)='!'; %appending ! to the end
end
disp(string2)
output_length = len_string1 *2; %length of output
end

ind1 = 1; %start index for first string
ind2 = 1; %start index for second string
%Creating output
for j = 1:output_length
if(rem(j,2)==0) %even indices
output(j)=string2(ind2); %adding second string
ind2 = ind2+1; %incrementing the second string index
else %odd indices
output(j)=str1(ind1); %adding first string
ind1 = ind1+1; %incrementing the first string index
end
end

I hope the explanation is clear and is useful in your understanding. Thank you.

Add a comment
Know the answer?
Add Answer to:
MATLAB Function Name: vineConpilation Inputs: 1. (chan The first vine quote 2. (chan The second ine...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote...

    for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote Outputs: 1. (​char​) A “compilation” of the vines Background: It’s Sunday afternoon and you’re hanging out in your lounge, finishing off your Sprite Cranberry. Your Mom FriendTM (Jared, 19) walks in and yells at you for drinking soda for breakfast. Aggravated, you YEET the empty can down the hall as Jared drags you to the kitchen to make breakfast. You open the fridge to...

  • Function Name: stPaddysFeast Example search- Inputs 1 (struct) A MxN structure array 2. double) A...

    Using MATLAB, please read question well Function Name: stPaddysFeast Example search- Inputs 1 (struct) A MxN structure array 2. double) A 1x2 vector of your starting position: [row, column] next: [1, 3] next: [1, 1] next: [2, 1) food: 'potato food potato next: 2, 3] step 2 food: start next: [2, 2] food: 'potato' step 3 Outputs next [1, 21 food: food: 1. (ohar)A descriplion of how mary potatoes you found ad where you stopped looking step 4 (stop) Background...

  • Problem 1 In this problem, you will write two functions. The first function takes in a...

    Problem 1 In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The second function takes in the first and last name and returns a string that is lastname_firstname and uses the previous function to remove any dashes (-) in the name. Note that you’ll be testing it by calling it from the command line; you’ll call it from a script in problem 3. Deliverables: Function file that...

  • matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number...

    matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number of soldiers each line 2. (char)A file name, indluding extension, for the output file group number Formation1.txt: 1 Line 1 has the following line up: e 1 1 1 0 File Outputs: 21 Line 2 has the folloOwing line up: 1 1 1 1 1 1. A text file showing the soldiers formations 3 Line 3 has the following line up: e e 1...

  • matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number...

    matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number of soldiers each line 2. (char)A file name, indluding extension, for the output file group number Formation1.txt: 1 Line 1 has the following line up: e 1 1 1 0 File Outputs: 21 Line 2 has the folloOwing line up: 1 1 1 1 1 1. A text file showing the soldiers formations 3 Line 3 has the following line up: e e 1...

  • MATLAB code help!!! Function Name: sportsStats Inputs: 1. (double) An Nx5 array representing the stats of different foo...

    MATLAB code help!!! Function Name: sportsStats Inputs: 1. (double) An Nx5 array representing the stats of different football teams 2. (double) The cutoff for total penalties Outputs: 1. (double) An Mx5 array representing the updated stats Background: You just finished watching the Patriots defeat the Rams in Super Bowl LIII, and you just can't wait for the next season to start. However, instead of waiting around for the next football season, you decide to take matters into your own hands...

  • Function Name: ​fluxCapacitor Inputs: 1. (double) The current year 2. (double) Destination year 3. (double) Speed,...

    Function Name: ​fluxCapacitor Inputs: 1. (double) The current year 2. (double) Destination year 3. (double) Speed, in miles per hour Outputs: 1. (char) String stating whether you’re going back or forward into the future Background: Doc Brown has invited you on an adventure through time. As you two hop into the time-travelling Delorean, he inputs the current year and the destination year. As the Doc steps on the gas, he reminds you that you can’t interact with ANYONE, or you’ll...

  • MATLAB code help! Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2....

    MATLAB code help! Function Name: jackSparrow Inputs: 1. (double) A 1x2 vector describing your hand 2. (double) A 1x2 vector describing Jack Sparrow's hand 3. (double) A vector with the next cards to be drawn from the deck Outputs: 1. (char) A description of the game outcome Background: You're out at sea with the infamous Jack Sparrow, and it's a pretty calm day. Without anything better to do, Jack Sparrow challenges you to his favorite card game: BlackJack (Sparrow edition)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT