필터 지우기
필터 지우기

MATLAB letter grade from Excel file

조회 수: 4 (최근 30일)
Victor
Victor 2023년 10월 17일
댓글: Voss 2023년 10월 18일
I am trying convert the percentage grade I calulcated into letter grades and I do not know how to?
%a) Read the student's information into MATLAB using buil-in function
%readmatirx
data = readmatrix("ITEC2600_Sample_Grades.xls");
%b Create an anoymous fucntion to calculate the studet's final make
Final_Grade = @(data)max(data(:,2:3),[],2)*0.10 +data(:,4)*0.20+data(:,5)*0.20+data(:,6)*0.50;
Final= Final_Grade(data)
%c) find the letter for each grade level
  댓글 수: 2
Voss
Voss 2023년 10월 17일
Your percentage grade calculation is weighting the Project at 0.7 and the Final at 0:
Final_Grade = @(data)max(data(:,2:3),[],2)*0.10 +data(:,4)*0.20+data(:,5)*0.20+data(:,5)*0.50;
% ^ Project ^ Project again
I guess that should be Project at 0.2 and Final at 0.5:
Final_Grade = @(data)max(data(:,2:3),[],2)*0.10 +data(:,4)*0.20+data(:,5)*0.20+data(:,6)*0.50;
% ^ Final is column 6
Victor
Victor 2023년 10월 17일
ok thanks it

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

채택된 답변

Voss
Voss 2023년 10월 17일
You need to define which numeric grades map to which letter grades. For example:
letters = 'F':-1:'A';
letters(letters == 'E') = ''
letters = 'FDCBA'
thresholds = [0, 60:10:100]
thresholds = 1×6
0 60 70 80 90 100
Once you do that you may be able to use discretize as follows:
% read file:
data = readmatrix("ITEC2600_Sample_Grades.xls");
% calculate numeric grades:
Final_Grade = max(data(:,2:3),[],2)*0.10 +data(:,4)*0.20+data(:,5)*0.20+data(:,6)*0.50
Final_Grade = 56×1
74.3910 85.1200 86.6620 61.9830 64.3490 55.5670 71.5370 64.9400 85.3990 91.9400
% discretize numeric grades to indices in thresholds, then index into
% letters with those indices:
Final_Letter_Grades = letters(discretize(Final_Grade,thresholds))
Final_Letter_Grades = 'CBBDDFCDBACFCBCDACBBDDDDBCCDFCDCFCBCBCDCCDCCFCDDCCBFCCCD'
  댓글 수: 2
Victor
Victor 2023년 10월 17일
I am new at this, but like is there a way to do this using switch or if statements?
Voss
Voss 2023년 10월 18일
Sure.
% if statements:
N = numel(Final_Grade);
Final_Letter_Grades = char(zeros(1,N));
for ii = 1:N
if Final_Grade(ii) >= 90
Final_Letter_Grades(ii) = 'A';
elseif Final_Grade(ii) >= 80
Final_Letter_Grades(ii) = 'B';
elseif % etc.
% ...
else
% ...
end
end
% switch:
N = numel(Final_Grade);
Final_Letter_Grades = char(zeros(1,N));
for ii = 1:N
switch true
case Final_Grade(ii) >= 90
Final_Letter_Grades(ii) = 'A';
case Final_Grade(ii) >= 80
Final_Letter_Grades(ii) = 'B';
case % etc.
% ...
otherwise
% ...
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by