Required array is dependent on other arrays
조회 수: 1 (최근 30일)
이전 댓글 표시
The overall scores out of 100 students is included in the ascii file Scores.txt. The cut-off ratios for the letter grades are
Percentage, % Final Grade Letter
90 < Grade = A
80 < Grade < 90 = B
70 <= Grade < 80 = C
60 < Grade < 70 = D
Grade < 60 = F
Write a computer program in a script file that
a.Import the data in the text file Scores.txt using the load () command/function and assign it to a variable name Scores.
b.Assign the 1st column of Scores variable to ID and the second column to OG.
c.Determines the average score (S_avg) in the class. You can use the MATLAB built-in functions mean ().
d.Determines the number of students above the average (N_aavg). You can use the MATLAB built-in functions sum (). Please see the help of the functions sum() and mean () before using them.
e.Determine the number of students within +5% of the average (N_5avq).
f.Determines the number of students in each letter grade (N_A, N_B, N_C, N_D, N_F).
g.Determines the ID of students in each letter grade (ID_A, ID_B, IDC, ID_D, ID_F).
%<MY CODE WAS HERE>
HELP with:
The code below is what I have written so far, and have attached the txt file required.
I need help with part g, where it needs to create an array with the IDs of the students of that certain threshold.
when I run the code, it returns a single value rather than an array of required IDs.
Also, is there a better way to do parts d and e using sum() and mean() functions?
댓글 수: 0
채택된 답변
Chetan Bhavsar
2021년 10월 11일
편집: Chetan Bhavsar
2021년 10월 11일
ID_A = [];ID_B = [];ID_C = [];ID_D = []; ID_F = [];
for x = 1:size(Scores,1)
if OG(x)>90
ID_A(end+1) = ID(x);
elseif (OG(x)>=80) && (OG(x)<90)
ID_B(end+1) = ID(x);
elseif (OG(x)>=70) && (OG(x)<80)
ID_C(end+1) = ID(x);
elseif (OG(x)>=60) && (OG(x)<70)
ID_D(end+1) = ID(x);
elseif (OG(x)<60)
ID_F(end+1) = ID(x);
end
end
Also every for loop can be more generic by using size instead of hard coded 100
size(Scores,1)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!