Question

In: Computer Science

USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...

USING MATLAB
Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop.

%this code tests the function, myflip, which you will write below

v1 = 100*rand(1);

v1 = myflip(v1)

n = randi([2 100], 1, 1);

v2 = 100*rand(1,2*n);

v2 = myflip(v2)

n = randi([2 100], 1, 1);

v3 = 100*rand(2*n+1,1);

v3 = myflip(v3)

Solutions

Expert Solution

myflip.m file code:

function[v]=myflip(v)%% after function keyword return vector is there after functin nameinput parameter
    v=flip(v);%%flipping the vector and storig it in v
end%% end of function

testmyfilecode.m(just for testing program )

%this code tests the function, myflip, which you will write below

v1 = 100*rand(1)
disp('after myflip')
v1 = myflip(v1)

n = randi([2 100], 1, 1);

v2 = 100*rand(1,2*n)
disp('after myflip')
v2 = myflip(v2)

n = randi([2 100], 1, 1);

v3 = 100*rand(2*n+1,1)
disp('after myflip')
v3 = myflip(v3)

Output

since its not possible to show the full vector v3 iam giving the screenshot of end of v3 and front of flipped v3 so that output can be verified

code screenshot for function file


Related Solutions

#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the...
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the #file and return the contents.# # # - If the contents of the file can be interpreted as # an integer, return the contents as an integer. # - Otherwise, if the contents of the file can be # interpreted as a float, return the contents as a # float. # - Otherwise, return the contents of the file as a # string. #...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits and the multiplication of the digits. The input of this function is N (entered number) and the outputs are number_digits and sum_digits.
Using Python #Write a function called after_second that accepts two #arguments: a target string to search,...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8. there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.
Write a MATLAB script or function that returns the required initial velocity of the ping pong...
Write a MATLAB script or function that returns the required initial velocity of the ping pong ball required to launch it a specified distance. Use projectile motion equations. Keep in mind that the initial firing height will change depending on the proposed catapult design. Primary considerations in the catapult design are accuracy and repeatability as groups will be tasked with hitting the target (cup) repeatedly at distances ranging from 7 to 9 ft. (cup moved in 6 in. increments).
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should...
Write a function called HW5_P1 that accepts 1 input argument: an array, a. The function should output an array, b, that is computed as: b=3a+5. Write a MATLAB function called “fit_line” that accepts 2 input arguments: a column vector of x data and a column vector of y data. The nth element in the input arguments should correspond to the nth Cartesian data point i.e. (xn,yn). The function should compute and return 2 outputs: the slope, m, and the y...
Write a MATLAB function that accepts input vector x and returns the number of local maximums...
Write a MATLAB function that accepts input vector x and returns the number of local maximums of x with value between xmin and xmax. Ask user to input values xmin and xmax at the beginning of the procedure. Use vector x (the vector x from that file consists of 1000 numbers ranging from 0.0044 to 0.67).
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT