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 件のコメント
Asad Ahmed
Asad Ahmed 2021 年 8 月 10 日
I have a question. Is it possible to use the categorical function on a column of a cell array?
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 10 日
Yes

サインインしてコメントする。


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.

カテゴリ

Help Center および File ExchangeCategorical Arrays についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by