You may refer to the following two functions and create the actual ones.
function y= get_marks(id)
load marks
pos=find(marks(:,1)==id,1);
y=[marks(pos,2) marks(pos,3) marks(pos,4)];
end
function [final_mark, grade]=markscale(input)
final_mark=0.1*input(1)+0.2*input(2)+0.7*input(3);
if(final_mark>50)
grade='pass';
else grade='fail';
end
end
Here I have stored the marks in a mat file called 'marks' which has a variable 'marks' inside it. However, if you are using a text file you may read data using 'fscanf' function.
To generate a random matrix for marks I have used the following code.
marks(:,1)=1:10;
marks(:,2)=randi([1 100],10,1);
marks(:,3)=randi([1 100],10,1);
marks(:,4)=randi([1 100],10,1);
Here the first column is student id and the rest three columns are the marks.
Best Answer