Effacer les filtres
Effacer les filtres

Convert final grade letter into categorical array.

1 vue (au cours des 30 derniers jours)
Asad Ahmed
Asad Ahmed le 10 Août 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.

Réponses (2)

Scott MacKenzie
Scott MacKenzie le 10 Août 2021
Modifié(e) : Scott MacKenzie le 10 Août 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 commentaires
Asad Ahmed
Asad Ahmed le 10 Août 2021
I have a question. Is it possible to use the categorical function on a column of a cell array?
Scott MacKenzie
Scott MacKenzie le 10 Août 2021
Yes

Connectez-vous pour commenter.


Steven Lord
Steven Lord le 10 Août 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.

Catégories

En savoir plus sur Categorical Arrays dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by