Please show how to write a function for this problem. Please also show output to confirm the function runs properly. Thank you.
Exam Statistics in Vectors
My Solutions >
Code has already been provided to define a function named examStats that receives column vectors of student test scores for three different exams as inputs into three variables: exam1Scores, exam2Scores, and exam3Scores. The position of each individual student's score is consistent through the three input vectors (e.g. the score for student number 5 is the fifth element in each of these vectors). Add code to this function to do the following:
Compute the mean test score for each student (i.e. the average of the student's three scores) and assign these values as a column vector to the output variable named studentMeans. Use the appropriate built-in function to compute the mean score for each exam and assign these three values to a row vector named examMeans with the mean scores for exams 1, 2, and 3 as the first, second, and third elements respectively. Use the appropriate built-in function to compute the standard deviation for each exam and assign these three values to a row vector named examStDev with the results for exams 1, 2, and 3 as the first, second, and third elements respectively.
Solve this problem using vectorized code (i.e. do not use a loop in your solution). Note the variables exam1Scores, exam2Scores, and exam3Scores are assigned values as function inputs. Do not overwrite these values in your code.
Function
Save C Reset MATLAB Documentation
function [studentMeans, examMeans, examStDev] = examStats(exam1Scores, exam2Scores, exam3Scores) %enter commands for the function here
Code to call your function
C Reset
exam1Scores = [99; 83; 77; 74; 88; 86; 91; 94; 62];
exam2Scores = [89; 82; 97; 64; 68; 76; 78; 84; 90];
exam3Scores = [92; 89; 86; 66; 73; 81; 83; 64; 85];
[studentMeans, examMeans, examStDev] = examStats(exam1Scores, exam2Scores, exam3Scores)