Using arrays in Matlab. 2. (10 points) A script stores quiz data for a class in
ID: 644541 • Letter: U
Question
Using arrays in Matlab.
2. (10 points) A script stores quiz data for a class in an array of structures called students. Each element in the array is a structure that has two members: student-id, the integer student ID number, and score, a vector comprising three quiz scores. The structure might look like the following for a student with ID number 44: Write a function called my-average that takes as input an array of such structures and returns as output. an array of structures wherein each array element is a structure comprising two members: student_id, the integer student ID number, and average, the mean of the three quiz scores. Your function must correctly handle input arrays of arbitrary length. An example of a script that will invoke your function is shown below. The out_struct array returned by the function will contain: As with the previous problem, submit only the my-average function as per the specification on Cody. We will take care of creating and passing the appropriate array of structures to your function and checking the output structure for correctness.Explanation / Answer
function outS = my_average( students )
s=struct('student_id',cell(1),'average',cell(1));
outS=repmat(s,length(students));
for i=1:length(students)
outS(i).student_id=students(i).student_id;
outS(i).average=sum(students(i).score);
outS(i).average=outS(i).average/length(students(i).score);
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.