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

조회 수: 1 (최근 30일)
Alaa Mohammed
Alaa Mohammed 2021년 5월 12일
편집: Adam Danz 2021년 5월 19일

답변 (3개)

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