Can anybody help me with the two questions below in the image? Thanks in advance

1 次查看(过去 30 天)

回答(3 个)

Sulaymon Eshkabilov
% 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
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
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.

DGM
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 个评论
Adam Danz
Adam Danz 2021-5-19
编辑:Adam Danz 2021-5-19
What is that mean?
Why don't you try to implement those grades into one of the solutions here?
I really don't think this forum shouldn't be used to do people's homework but that's just my opinion.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by