Can anybody help me with the two questions below in the image? Thanks in advance
1 回表示 (過去 30 日間)
古いコメントを表示
2 件のコメント
回答 (3 件)
Sulaymon Eshkabilov
2021 年 5 月 13 日
% Simple and easy answer here is to use logical indexing and categorical array approaches along with table, e.g.:
ID = (1:10)';
ALL=[ID, PE EM PS]; % This is your predefined/already entered table of student grades.
EX2 = array2table(ALL,'VariableNames', {'ID', 'P_E', 'E_M', 'P_S'}); %Given data table. You can change table headers if needed.
CC = cell(size(ALL(:,2:4)));
CC(ALL(:,2:4)>90)={'A'};
CC(ALL(:,2:4)<=90 & ALL(:,2:4)>80)={'B'}
CC(ALL(:,2:4)<=80 & ALL(:,2:4)>70)={'C'}
CC(ALL(:,2:4)<=70 & ALL(:,2:4)>60)={'D'}
CC(ALL(:,2:4)<=60)={'F'}
CC = categorical(CC);
PE = CC(:,1);
EM = CC(:,2);
PS = CC(:,3);
TT = table(ID, PE, EM, PS)
Num_C = sum(CC=='C', 'all')
fprintf('# of low graded students are %d \n', Num_C)
%% Good luck
3 件のコメント
Image Analyst
2021 年 5 月 15 日
For Exercise 2A, your counts of 3 for the As and Fs are correct. The exercise is missing the counts for the other grades so you need to add that in.
Image Analyst
2021 年 5 月 13 日
You can either do this by doing a series of comparisons like
numCs = sum(grades > 70 & grades <= 80) % Compute the number of "C" grades.
or you can specify the edges and pass the edges into histogram() or histcounts().
You forgot to show us the way you did it, so we cannot correct your code for you.
0 件のコメント
DGM
2021 年 5 月 13 日
編集済み: DGM
2021 年 5 月 13 日
Consider this partial solution for part 2 using some simplifications based on the binning and a basic lookup table. This could be made more robust, but let's just be simple for now.
% make some random test grades
G = randi(40,10,3)+60
sn = 1:10;
examnames = {'basket weaving','daisy picking','alligator wrestling'};
lut = {'F','F','F','F','F','F','D','C','B','A'};
bin = ceil(G/10);
gradeletter = lut(bin);
table(sn',[gradeletter{:,1}]',[gradeletter{:,2}]',[gradeletter{:,3}]', ...
'variablenames',['student id',examnames])
gives
ans =
10×4 table
student id basket weaving daisy picking alligator wrestling
__________ ______________ _____________ ___________________
1 C D A
2 D B C
3 D C A
4 A B A
5 A C B
6 D A D
7 B A A
8 B A A
9 D A B
10 D D B
"Find the number of students with minimum grades" sounds awfully vague do me. Does that mean "minimum passing grade" (i.e. D) or "minimum valid grade" (i.e. F)?
2 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!