Hi This is my matlab class quiz problem I cant get that I ne
Hi. This is my matlab class quiz problem.
I can\'t get that.
I need you guys help.
For the following data, show using code that calculates which contestant had the highest score The first column is the contestant ID #, and the second column is the scores. 11 56 42 78 23 92 4 82 50 50 You must use only one builit-in function (max) to get the row where that max is found, then show the corresponding value from the contestant ID column using an output function Your Answer x11 56,42 78.23 92.4 8250 50 la bj-max(x( 2) tprintfonax constenstan ID %Score(b), x(3), assuming the data is assigned to matrix x [a,b-max(x( 2 )) --8 t returns the max in a and the location in b. use disp to show b Solution
Understanding max function of Matlab is the key to answer this function.
[a,b] = max(R) -> gives maximum value in a and index of that row in b
for example let say R = [1;4;3;2] then max(R) gives [4,2] as 4 is maximum and it is located in 2 row
Code with comments:
x = [11 56,42 78;23 92;4 82;50 50] % creating a 2d array with contestsnt ID and scores as columns
[a,b] = max(x(:2)) % selecting maximum of the second column scores with maximum value score index in b
disp(x(b,1)) % we have to show contestant ID only,not whole row.
