MATLAB Answers

Convert final grade letter into categorical array.

조회 수: 1(최근 30일)
Asad Ahmed
Asad Ahmed 2021년 8월 10일
답변: Steven Lord 2021년 8월 10일
Class_List = readcell('ClassList_2600.xls');
N = size(Class_List);
num_rows = N(1);
for i = 2:N
Test = ((Class_List{i,4} + Class_List{i,5}) / 2) * 0.1;
Assignment = Class_List{i,3} * 0.1;
Midterm = Class_List{i,6} * 0.3;
Final = Class_List{i,7} * 0.5;
grade = round(Test + Assignment + Midterm + Final);
if grade >= 90
Class_List{i,8} = grade;
Class_List{i,9} = {'A+'};
elseif grade >= 80 && grade <= 89
Class_List{i,8} = grade;
Class_List{i,9} = {'A'};
elseif grade >= 70 && grade <= 79
Class_List{i,8} = grade;
Class_List{i,9} = {'B'};
elseif grade >= 60 && grade <= 69
Class_List{i,8} = grade;
Class_List{i,9} = {'C'};
elseif grade >= 50 && grade <= 59
Class_List{i,8} = grade;
Class_List{i,9} = {'D'};
elseif grade < 50
Class_List{i,8} = grade;
Class_List{i,9} = {'E'};
end
end
a = Class_List(:,9);
pie = categorical(a);
So basically, I have a 26x9 cell array that shows a class list. It contains names, student ID, marks for related work, their final grade number and letter associated with it (i.e A, B, C, D, etc). I don't know how to use the categorical function. What I have above is my work.

답변(2개)

Scott MacKenzie
Scott MacKenzie 2021년 8월 10일
편집: Scott MacKenzie 2021년 8월 10일
% test data containing student letter grades
C = { 'A' 'C' 'D' 'A' 'D' 'B' 'B' 'C' 'A' };
% define C to be categorical
C = categorical(C);
% display the categories
categories(C)
ans = 4×1 cell array
{'A'} {'B'} {'C'} {'D'}
% output number of students in each letter grade category
n = countcats(C)
n = 1×4
3 2 2 2
% present in pie chart
pie(n)
  댓글 수: 2

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


Steven Lord
Steven Lord 2021년 8월 10일
I would make a vector of grade numbers then use discretize to create a categorical array from that vector of grade numbers. See the "Group Data into Categorical Array" example on the documentation page for the discretize function as a model you can use.

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by