所以我在这里有这个代码,试图加载一个35x5数据集的考试成绩的excel文件,并计算每个学生的平均考试成绩(35名学生,每次5个考试)。然后它应该根据平均分数吐出每个学生所获得的字母等级。
%65 P
%Penna Garrett
%Exam Grades part 2
%Loading the Exam Scores from Excell
grades = xlsread ('Exam_Grades_Data_Part2')
%Don't need to do display because xlsread throws it into command window
%Letter grade earned based on this scale of average test scores:
%0-59 = E
%60-69 = D
%70-75 = C
%76-79 = C+
%80-85 = B
%86-89 = B+
%90-100 = A
%To Calculate the average for all rows I will use a loop function
temp = size(grades)
%Here is my 'for' function
loopend = size(grades,1)
for i=1: loopend
average(i) = mean(grades(i,1:5));
if (average(i) <= 59)
letter{i} = 'E' ;
elseif (average(i) <= 69)
letter{i} = 'D' ;
elseif (average(i) <= 75)
letter{i} = 'C' ;
elseif (average(i) <= 79)
letter{i} = 'C+' ;
elseif (average(i) <= 85)
letter{i} = 'B' ;
elseif (average(i) <= 89)
letter{i} = 'B+' ;
elseif (89 < average(i) <= 100)
letter{i} = 'A' ;
end
end
display('Hopefully you have recieved the grade you wanted. If not, I may see you next year! Dr. P')
display (letter)
我不能为我的生活弄清楚我得到的错误。 它在命令窗口中说:
将单元格内容分配给非单元格数组对象。
S65_Garrett_Penna_07(第42行)中的错误
letter {i} ='A';
答案 0 :(得分:1)
你可能有变量&#34;字母&#34;在工作区中作为非单元格数据类型(如双精度型)。您可能应该将此变量初始化为for循环上方的某个单元格,
letter = {};