Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Topics: Input and Output in MATLAB; Script .m files; Built in functions A profes

ID: 3871783 • Letter: T

Question

Topics: Input and Output in MATLAB; Script .m files; Built in functions

A professor wants a MATLAB script that will allow him to enter the name of a course and a vector containing all the scores for a test. The script will then print a report with the course’s name at the top, I will compute the mean, median and the ranked sort list of the scores showing the ranking number with the score.

Outline: Display a short welcome message to the user Prompt the user to input the name of the course and test number Prompt the user to input the vector of the test grade Using the built-in functions compute the mean and median Using the built-in function sort the scores in descending order Display a brief report, including all of the above indicated inputs and result(s), which is formatted in a logical and readable fashion

Note(s): Your program should produce output identical (when given the same input(s) ) to the sample run(s) below, values and format. You will need to use the fprintf as well as mean(), median(),and sort().

Sample Run(s):

>> f17_p3 Enter the Course Name:

CompSci 240

Enter the test's number: 2

Enter the scores on one line inside brackets []: [1 2 3 4 5 5 6 6 7 8 9 9 10]

CompSci 240

Test #2

The mean is 5.77

The median is 6.00

Rank Score 1 10.00 2 9.00 3 9.00 4 8.00 5 7.00 6 6.00 7 6.00 8 5.00 9 5.00 10 4.00 11 3.00 12 2.00 13 1.00

Goodbye!

>>

Explanation / Answer

program:--

prompt='Enter the Course Name: ';
name=input(prompt,'s'); %read test name
prompt='Enter the test number: ';
number=input(prompt);   %read test number
marks=input('Enter the scores on one line inside brackets: '); %read marks as vector
disp(name); %display test name
fprintf('Test #%d ',number);   %print test number
mean1=mean(marks); %mean
fprintf('The mean is %f ',mean1); %print mean
median1=median(marks); %median
fprintf('The median is %f ',median1); %print median
marks1 = sort(marks,'descend'); %sort marks
[r,c] = size(marks1);   %get vector size
fprintf('Rank Score: ');
for i=1:1:c
    fprintf('%d %.2f ',i,marks1(1,i)); %print marks as rank wise
end

Output:--

>> sort_mat_single_ele
Enter the Course Name: CompSci 240
Enter the test number: 2
Enter the scores on one line inside brackets: [1 2 3 4 5 5 6 6 7 8 9 9 10]
CompSci 240
Test #2
The mean is 5.769231
The median is 6.000000
Rank Score: 1 10.00 2 9.00 3 9.00 4 8.00 5 7.00 6 6.00 7 6.00 8 5.00 9 5.00 10 4.00 11 3.00 12 2.00 13 1.00 >>