Convert final grade letter into categorical array.
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (2)
Scott MacKenzie
on 10 Aug 2021
Edited: Scott MacKenzie
on 10 Aug 2021
% 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)
% output number of students in each letter grade category
n = countcats(C)
% present in pie chart
pie(n)
Steven Lord
on 10 Aug 2021
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.
0 Comments
See Also
Categories
Find more on Categorical Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!