Question

Write a script file that will compare entries in vector V to entries in vector M...

Write a script file that will compare entries in vector V to entries in vector M and determine how many entries in V are greater than the same entry in M, equal to the same entry in M, and less than the same entry in M. For example, V(1) is 7 and M(1) is 6, thus for this entry, V is greater than M.

V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]

M = [6 4 3 -2 3 -9 -1 3 7 -2 2 -9]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]
M = [6 4 3 -2 3 -9 -1 3 7 -2 2 -9]
increase_count = 0;
decrease_count = 0;
no_change_count = 0;
for i=1:length(V)
    if V(i) < M(i)
        increase_count = increase_count+1;
    elseif V(i) > M(i)
        decrease_count = decrease_count+1;
    else
        no_change_count = no_change_count+1;
    end
end
fprintf("Number of times entries in V are greater than the same entry in M is %d\n", increase_count)
fprintf("Number of times entries in V are smaller than the same entry in M is %d\n", decrease_count)
fprintf("Number of times entries in V are equal to the same entry in M is %d\n", no_change_count)

Add a comment
Know the answer?
Add Answer to:
Write a script file that will compare entries in vector V to entries in vector M...
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
  • Write a MATLAB script file that will sum all the positive entries in V and stop...

    Write a MATLAB script file that will sum all the positive entries in V and stop summing once the sum reaches or exceeds 20(while loop). An fprintf statement should be used to display the value for the sum to prove it has reached or exceeded 20, and the number of entries to reach this value should be displayed. V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7] Reminder: don’t use the built-in function, sum. Use...

  • In Matlab write a script that does the following. 1. Creates a row vector v =...

    In Matlab write a script that does the following. 1. Creates a row vector v = [3, 6, 9, 9, 15], and then manipulates v to create each of the following vectors (and then displays the result of each): (a) a = [9, 36, 81, 81, 225] (b) b = [ 1 3 , 1 6 , 1 9 , 1 9 , 1 15 ] (c) c = [1, 2, 3, 3, 5] (d) d = [15, 9, 9,...

  • Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...

    Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15) b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only...

  • S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write...

    S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...

  • Projection vector, p, of w on V V = (6,6) p = (4.4) W = (6,2)...

    Projection vector, p, of w on V V = (6,6) p = (4.4) W = (6,2) 1 2 3 4 5 6 Visualising vector projection Exercise 2 The projection of w= is given by the projection formula below: Plot all three vectors using plot and make the projection vector pa dashed line. Write a script from scratch to produce the figure below (click to enlarge). Make sure the axes are equal. Show/hide hint Optional extra challenge Upload your M-file that...

  • MATLAB Define the following computer programming terms and give an example of each. MATLAB example Sequence...

    MATLAB Define the following computer programming terms and give an example of each. MATLAB example Sequence Selection structure- Repetition structure - Relational operators (True = 1, False = 0) Logical operators (True = 1, False =0) And Or Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Not ans ans Type the following relational operator commands into MATLAB in the command window one at a time. Write the results to...

  • mathlab Q2. Write a script file that accepts the user input of array of any size...

    mathlab Q2. Write a script file that accepts the user input of array of any size then uses nested for loops to find the minimum and maximum elements in the array. See slides 43,44 & 45 for hints Use the following 2 arrays to test your script: A- A 10 10 -4 17 2 5 0 13 -7 9 AND لیا M -1 5 -7 4 7 17 6 9 10 Sample Outputs: For the given array, the min. value...

  • provide a python script please For the following vectors and matrices, using the NumPy library, write...

    provide a python script please For the following vectors and matrices, using the NumPy library, write a script file that determines the solution for x given by the equation x-(A AT)b-Cd where AT denotes the transpose of A 1 2 3 4 16 12 8 4 A-2 4 6 8 3 6 9 12 4 8 12 16 C-12 9 6 3 8 6 4 2 4 3 2 1 4 The output to the command terminal prompt within Spyder...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • Question 8 Data Structures - arrays, matrices and strings (a) Write a MATLAB script that will...

    Question 8 Data Structures - arrays, matrices and strings (a) Write a MATLAB script that will copy all of the negative values in a matrix,M, to a new vector, N.[7 marks] (b) Write a MATLAB script that reads in two strings from the user and comparesthem, printing’same’if they are the same or the indexes of the characterswhich differ if they are different. For example, if the user typed in ’car’and ’cat’, the script would print ’the words differ in characters:...

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