Question

for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote...

for matlab

Function Name: ​vineCompilation

Inputs:

  1. (​char​) The first vine quote

  2. (​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 find some tortillas, eggs, and wow! Look at all that chicken! Jared says he could make the perfect breakfast tacos if he only had some fre sha voca do. You guys get your fre sha voca dos and Jared makes you some scrumptious breakfast tacos. To repay him, you make him a compilation of his favorite vines, with a little help from your friend MATLAB!

Function Description:

Given two string inputs, swap the first and second halves of the first input and sort the second input in reverse alphabetical order. Then, “compile” 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. If one string is longer than the other, add exclamation points to the end of the shorter string so the strings are the same length.

Example:

vine1= ' '
vine2= ' '
compilation = vineCompilation(vine1, vine2)
vine1 → ' '
vine2 → ' '
compilation → '​p​v​t​s​y​r​.​o​ ​o​Y​h​E​f​E​e​T​d​!​c​T​a​h​a​i​ ​s​ ​​​c​!a​ ​!​n​!​ ​!​e​!m​ ​!​'

Notes:

  • ● If the first string's length is an odd number, split it into two unequal halves with the first half being longer than the second, then swap them.

    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:

Output:

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:
for matlab Function Name: ​vineCompilation Inputs: (​char​) The first vine quote (​char​) The second vine quote...
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
  • MATLAB Function Name: vineConpilation Inputs: 1. (chan The first vine quote 2. (chan The second ine...

    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: It's Sunday aftemoon and you're 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...

  • Homework 02-Vectors, Strings, and Masking Function Name: forecast Inputs 1. (char) A character vector of the current fo...

    Homework 02-Vectors, Strings, and Masking Function Name: forecast Inputs 1. (char) A character vector of the current forecast 2. (char) The word to be replaced 3. (char) The new word to put into the forecast Outputs 1. (char) The updated forecast description Banned Functions strrep), replace), regexprep() Background You have recently started your internship as a weather engineer at the local news station. Unhappy with how the curment forecasts are described as 'gloomy" and 'cold, you decide to use MATLAB...

  • Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of...

    Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of text file to write to Outputs: none File Outputs: 1. A text file containing all the permutations of the anagram Banned Functions: perms(), permute(), ipermute(), nchoosek (), combnk() Background: You guys know what do. You are professional MATLAB now, you got this! Function Description: Given a string, recursively determine all the unique ways to rearrange the letters. (i.e al the unique permutations). For example,...

  • 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...

  • 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 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using...

    matlab 28 pts Question 8 Problem 4. Write the following function. Do NOT hard code using any of the examples. Your function should work for all possible inputs as specified by the problem. Hard coding will result in significant point loss. (B) (28 Points) Function Name: birthday Party Input (2): (char) An Mx 11 array formatted with information about various birthdays (char) An MxN array of names Output (l): (char) A string containing information about the best birthday Function Description:...

  • Function Name: hahaYes Inputs: 1. 2. (char) The filename of an Excel file containing word counts ...

    using MATLAB Function Name: hahaYes Inputs: 1. 2. (char) The filename of an Excel file containing word counts from various works (cell) A 2xN cell array of words and how many times they occur in the unknown work Outputs: 1. (cell) A 1x3 vector of the closest matches to the unknown work Background You do not understand this reference Function Description: The Excel file that you are given contains data on how many times certain words appear in different works...

  • 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...

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