function out = weighted(ha, qa, ea) % place the code for the weighetd sub-funcit
ID: 3799075 • Letter: F
Question
function out = weighted(ha, qa, ea)
% place the code for the weighetd sub-funciton here
end
%---------------------------------
function out = finalGrade(in)
% place your code for the finalGrade sub-function here
end
Explanation / Answer
Here is the code you asked me for:
function fg = gradeCalc(h, q, e)
%The function should call a sub-function that creates a vector for each
%matrix with the average value for each row.
ha = average(h);
qa = average(q);
ea = average(e);
%The returned vectors should then be passed to another sub-function
%that calculates their weighted value, and returns a matrix with all
%the weighted values.
weightedMatrix = weighted(ha, qa, ea);
%Finally the returned weighted matrix should be passed to the third
%sub-function that returns a vector with the final grade for each
%student.
fg = finalGrade(weightedMatrix);
end
function out = average(in)
[rows, cols] = size(in);
for i = 1 : rows
out(i) = 0.0;
for j = 1 : cols
out(i) = out(i) + in(i, j);
end
out(i) = out(i) / cols;
end
end
function out = weighted(ha, qa, ea)
%30% homework, 30% quizzes and 40% exams.
for i = 1 : length(ha)
out(i, 1) = ha(i) * 30.0 / 100.0;
out(i, 2) = qa(i) * 30.0 / 100.0;
out(i, 3) = ea(i) * 40.0 / 100.0;
end
end
function out = finalGrade(in)
[rows, cols] = size(in);
for i = 1 : rows
out(i) = in(i, 1) + in(i, 2) + in(i, 3);
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.