Convert final grade letter into categorical array.

1 Ansicht (letzte 30 Tage)
Asad Ahmed
Asad Ahmed am 10 Aug. 2021
Beantwortet: Steven Lord am 10 Aug. 2021
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.

Antworten (2)

Scott MacKenzie
Scott MacKenzie am 10 Aug. 2021
Bearbeitet: Scott MacKenzie am 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)
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 Kommentare
Asad Ahmed
Asad Ahmed am 10 Aug. 2021
I have a question. Is it possible to use the categorical function on a column of a cell array?

Melden Sie sich an, um zu kommentieren.


Steven Lord
Steven Lord am 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.

Kategorien

Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by