# Required array is dependent on other arrays

1 view (last 30 days)
Humza Khan on 11 Oct 2021
Edited: Humza Khan on 18 Oct 2021
The overall scores out of 100 students is included in the ascii file Scores.txt. The cut-off ratios for the letter grades are
80 < Grade < 90 = B
70 <= Grade < 80 = C
60 < Grade < 70 = D
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?

Chetan Bhavsar on 11 Oct 2021
Edited: Chetan Bhavsar on 11 Oct 2021
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)
Humza Khan on 11 Oct 2021
Thank you!

### Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!