Hello, I'm trying to do an assignment that has to calculate mean and assign letter grades to grades from an excel document. I've successfully got the mean but I cant get the letter grade part to work. Any suggestions?
endgradebook = xlsread('E');
display (gradebook)
for i=1:95
average(i)= mean(gradebook(i,1:5));
end
display(average)
for i=1:95
average(i)=mean(gradebook(i,1:5);
if(average(i)<=59)
letter{i}= 'F';
elseif(average(i)<=69)
letter{i}= 'D';
elseif(average(i)<=79)
letter{i}= 'C';
elseif(average(i)<=89)
letter{i}= 'B';
else
letter{i}= 'A';
end
end

댓글 수: 3

Walter Roberson
Walter Roberson 2018년 10월 14일
Your second calculation of average(i) is not needed because you have already calculated it a few lines above.
There is nothing obviously wrong with your assignment of letter grades; what difficulty are you observing?
When you use a cell array for the letter grades instead of a character array or character vector, that is a valid thing to do, but a character array or character vector would also be valid under the condition that each letter grade is exactly one character. For example, a grade of A- is handled easily by a cell array but not a character vector (but it could be handled with a character array if you were careful.)
Not_sharpest_tool.mat
Not_sharpest_tool.mat 2018년 10월 14일
Thanks, the problem was the second mean calculation. I erased it and it worked.
Walter Roberson
Walter Roberson 2018년 10월 14일
Should not have made a difference, it was just repeating what had already been calculated.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2018년 10월 15일

0 개 추천

Your second calculation of mean is missing a closing parentheses, though that may just be a copy/paste error.
...
for i=1:95
average(i)=mean(gradebook(i,1:5);
...

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

질문:

2018년 10월 14일

답변:

2018년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by