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.
MATLAB Function Name: vineConpilation Inputs: 1. (chan The first vine quote 2. (chan The second ine...
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...
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 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 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 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 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, 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. (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)...