There are several ways to write this function, but it should contain a long list of elseif
s:
function [class] = DetermineClass(marks)
% Takes in an array of student marks and returns the degree classification as a string
overall_score = 0;
year_weights = [0.06 0.1 0.32 0.5]; %weights applied to the yearly averages
for i=1:4
%find the weighted average for each year, and add it to the overall_score
overall_score = overall_score + year_weights(i)*mean(marks(i,:));
end %for, i
if overall_score>=70
%overall_score is over 70
class = '1st class';
elseif overall_score>=68 && mean(marks(4,:))>=70
%overall_score is between 68 and 70, and 4th year average is >=70
class = '1st class';
elseif overall_score>=60
%overall_score is >=60, but less than 70 due to the previous cases
class = '2:1-class';
elseif overall_score>=50
%overall_score is >=50, but less than 60
class = '2:2-class';
elseif overall_score>=40
%overall_score is >=40, but less than 50
class = '3rd-class';
elseif overall_score>=38
%overall_score is >=38, but less than 40
class = 'resit';
else
%no other classifications
class = 'fail';
end %if, overall_score>=70
fprintf('Degree class was %s \n', class)
end %function, DetermineClass
As for the classification that each student attains, you should find that...
load './data/studentMarks' %load the marks into the workspace
DetermineClass(student1);
DetermineClass(student2);
DetermineClass(student3);
DetermineClass(student4);
DetermineClass(student5);
DetermineClass(student6);
DetermineClass(student7);
Degree class was 2:1-class Degree class was 2:2-class Degree class was 1st class Degree class was 2:2-class Degree class was 3rd-class Degree class was fail Degree class was resit