1.4k views
2 votes
Write a MATLAB program in a script file that calculate the average, standard

deviation, and median of a list of grades as well as the number of grades on
the list. The program asks the user (input command) to enter the grades as
elements of a vector. The program then calculates the required quantities
using MATLAB's built-in functions length, mean, std, and median.
The results are displayed in the Command Window in the following format:
"There are XX grades." where XX is the numerical value.
"The average grade is XX." where XX is the numerical value.
"The standard deviation is XX." where XX is the numerical value.
"The median grade is XX." where XX is the numerical value.
Execute the program and enter the following grades: 92, 74, 53, 61, 100, 42,
80, 66, 71, 78, 91, 85, 79, and 68.

User HHK
by
4.9k points

2 Answers

5 votes

Answer:

Complete Matlab code along with explanation and output results are given below.

Matlab Code:

clear all

close all

clc

input_grades = input('Enter the grades as elements of a vector ');

len = length(input_grades);

fprintf('There are %.2f grades\\', len);

Mean = mean(input_grades);

fprintf('The Average grade is: %.3f\\', Mean);

STD=std(input_grades);

fprintf('The Standard Deviation is: %.3f\\', STD);

Median = median(input_grades);

fprintf('The Median grade is: %.2f\\', Median);

Output:

Enter the grades as elements of a vector [92,74,53,61,100,42,80,66,71,78,91,85,79,68]

There are 14.00 grades

The Average grade is: 74.286

The Standard Deviation is: 15.760

The Median grade is: 76.00

Step-by-step explanation:

The user provides input vector of grades

Using the built-in functions of Matlab the length, mean, standard deviation and median of the grades are calculated and printed.

%.2f is a text formatting command that means show up to 2 decimal digits and convert the floating point values to text.

The input vector provided in the question is tested and the program is working correctly.

Write a MATLAB program in a script file that calculate the average, standard deviation-example-1
User Eric Chu
by
4.9k points
2 votes

Answer:

Code in MATLab is given as below:

Step-by-step explanation:

grade = input('Enter the grades as elements of a vector ');

x1 = length(grade);

fprintf('There are %5.2f grades\\',x1);

x2 = mean(grade);

fprintf('The average grade is %5.2f \\',x2);

x3=std(grade);

fprintf('The standard deviation is %5.2f \\',x3);

x4 = median(grade);

fprintf('The median grade is %5.2f \\',x4);

User Dominus
by
5.5k points