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?

采纳的回答

C B
C B 2021-10-11
编辑:C B 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 CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by