Matlab Grade book help --drop one lowest score and assigning letter grade

Hi I am building a gradebook that allows me to drop the lowest assignment score and only takes 10 assignment scores and adds all the test scores. I need to assign a letter grade to each student.
Here is some data
I am stuck on dropping the lowest score and assigning students to a grade in my function. if there is a better way of doing it without a function... please tell me...
function [sumarr] = grades(structure, field)
% FUNCTION GRADES accepts any cell array value and assigns a letter
% all data entered must be transposed from rows to colums please remember
% to transpose data example transposedata = data' ---> data = [FILE that
% was imported]
%DEFINE VARIABLES
% ii -- index variable
ii =0 ;
array =[];
for ii = 1:length(structure)
%build an array
array = [array structure(ii).(field)];
end
% if one grade is less than 2, drop the score.
% assign Letter grades
%sum of all grades
sumarr = sum(array);
end

3 个评论

How do you store your grades. like a struct: persons.torry.grade1.1 or a cell array. It makes a different when sorting the arrays.
How are you doing on the new assignment?

请先登录,再进行评论。

 采纳的回答

Can you try just subtracting the min, something like
array = [structure.(field)]; % All items - no loop over ii needed.
arraySum = sum(array) - min(array);

8 个评论

how would you do it if you were storing only the data in a cell array?
Try this:
% Create random cell array.
ca = cell(10,10);
for col = 1 : 10
for row = 1 : 10
ca{row, col} = randi(99, 1,1);
end
end
% Transpose like the homework directions said
ca = ca';
celldisp(ca);
% Extract column 3, for example.
columnSum = cell2mat(ca(:,3))
theSum = sum(columnSum) - min(columnSum)
You will find it very beneficial to read this : http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
How would you assign letter grades to arraySum?
What ways did you think of? You could do it several ways but probably the easiest is to use an if/elseif series to see what range the sum falls into.
Yeah that's how I did it.
if (arraySum >= 90 && arraySum <= 100)
fprintf(' final grade : %.3f\t A\n', arraySum);
elseif (arraySum >=80 && arraySum <=89)
fprintf(' final grade : %.3f\t B\n', arraySum)
elseif (arraySum >=70 && arraySum <=79)
fprintf(' final grade : %.3f\t B\n', arraySum)
elseif (arraySum >=60 && arraySum <=69)
fprintf(' final grade : %.3f\t B\n', arraySum)
elseif (arraySum >=0 && arraySum <=59)
fprintf(' final grade : %.3f\t B\n', arraySum)
else
printf('ERROR: invalid grade\n');
end
OK, good. But, Wow. You're very generous. You can get an A if you have more than 90, but if not, you'll get no worse than a B. Anyway, if you're all set and need no further advice on this topic, can you mark the answer as Accepted? Thanks in advance.
ImageAnalyst has already answered your question. Just one more note:
another way of grading without multiple if/else is this
levels=[59 69 79 89];
GradeLetter={ 'F', ...
'D', ...
'C', ...
'B', ...
'A'};
if (arraySum<0 || arraySum >100)
error('Imposible grade')
else
fprintf(' final grade : %.3f\t %s\n', ...
arraySum, ...
GradeLetter{imquantize(arraySum,levels)} )
end
This makes it easier to change the code and add more grade levels later, such as B+, B-, A+, A-
imquantize() is part of image processing though. You need to have that toolbox.
I am getting issues with my statements.... since I have an array with data = [93.280 70.500 67.980 23.940 95.430 89.950 85.600 94.860 88.310 75.740 82.570 73.330 92.860 91.760 83.610 88.660 82.310 87.380 76.790 69.860 90.610 86.910 97.370 73.420 ]; I apologize for not writing this solved but I wanted to make sure I get this grade assignment right.
function gradeAssignment( arraySum )
% gradeAsssignment function takes in array
% Gives the data set a letter grade outprint.
if (arraySum >= 90.0 & arraySum <= 100.0)
fprintf(' final grade : %.3f\t A\n', arraySum);
elseif (arraySum >=80.0 & arraySum <=89.0)
fprintf(' final grade : %.3f\t B\n', arraySum);
elseif (arraySum >=70.0 & arraySum <=79.0)
fprintf(' final grade : %.3f\t B\n', arraySum);
elseif (arraySum >=60.0 & arraySum <=69.0)
fprintf(' final grade : %.3f\t B\n', arraySum);
elseif (arraySum >=0.0 & arraySum <=59.0)
fprintf(' final grade : %.3f\t B\n', arraySum);
else
fprintf('ERROR: invalid grade\n');
end
end
The error that I encounter is that I run through all my data and it reads everything in the array but I get ERROR:invalid input.

请先登录,再进行评论。

更多回答(1 个)

类别

帮助中心File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by