How to calculate mean and standard deviation from a textfile

23 ビュー (過去 30 日間)
Braeden McKeown
Braeden McKeown 2021 年 3 月 10 日
編集済み: Braeden McKeown 2021 年 3 月 11 日
I have a text file of
100014 88.3
100109 96.9
100205 69.9
100263 90.5
100269 86.9
100293 76.2
100329 81.9
100412 87.1
100414 108.4
100419 103.1
100436 75.9
100501 104.8
100575 89.6
100640 84.4
100686 89.5
100741 83.4
100771 84.0
100846 94.6
100865 94.1
100934 94.2
100953 89.2
100990 76.8
101053 89.5
101132 95.6
101141 88.0
101234 91.6
101312 89.6
101361 82.8
101405 86.7
101450 79.6
101481 90.7
101532 77.2
101584 77.7
101666 79.5
101746 65.4
101811 94.3
101849 86.9
101931 79.8
101985 93.8
102021 73.5
102115 84.1
102203 83.2
102259 86.9
102322 86.9
102381 79.1
102402 84.6
102433 83.7
102481 88.9
102505 92.0
102590 92.1
102610 79.1
102633 85.3
102651 76.8
102674 77.5
102718 84.8
102750 94.9
102843 79.7
102887 87.3
102906 83.3
102997 92.2
103095 77.6
103139 85.0
103151 88.4
103177 92.1
103218 95.0
103278 85.4
103305 75.0
103366 79.9
103438 77.8
103461 100.3
103473 80.7
103503 89.7
103535 83.5
103578 90.7
103629 79.8
103638 75.5
103665 75.4
103746 88.0
103749 83.6
103842 83.5
103916 94.2
103965 86.7
104023 86.1
104047 95.3
104093 79.5
104190 62.7
104245 63.6
104298 56.8
104322 59.7
104371 51.0
104434 51.1
104502 59.0
104542 62.9
104579 74.6
104678 54.1
104682 59.5
104771 57.8
104863 46.1
104943 55.5
104953 47.0
104980 63.6
105014 52.7
105082 58.9
105096 54.9
105169 60.2
105180 54.5
105246 61.4
105296 63.0
105374 69.1
105446 57.1
105537 44.8
105627 53.0
105661 66.8
105731 51.5
105751 64.4
105755 59.1
105830 67.4
105881 45.9
105929 57.1
106020 50.7
106081 76.6
106143 63.5
106229 67.0
106310 51.6
106368 55.3
106387 56.6
106411 65.2
106500 56.5
106503 62.7
106552 45.4
106569 56.1
106667 53.1
106739 48.4
106790 61.5
106838 60.1
106844 58.5
106913 49.9
106918 65.4
106926 60.5
106979 56.4
106989 58.4
107071 56.6
107153 47.3
107226 56.5
107241 53.1
107307 52.1
107359 51.0
107457 54.9
107522 45.7
107603 64.4
107649 61.6
107693 58.2
107776 58.1
107785 53.3
107799 64.7
107817 57.5
107857 53.8
107941 66.8
108022 56.9
108029 54.6
108069 56.4
108122 53.0
The first column is a students id and the second coloumn is their grades
I am being asked to find the average of this using the mean function and also to find the standard deviation using the std function
data=load('testscores.txt','r');
StudentID=data(:,1);
Scores=data(:,2);
SD=std(Scores);
Ave=mean(Scores);
A=0;
B=0;
C=0;
D=0;
F=0;
High=0;
Average=0;
Low=0;
The mean and standard deviation are then plugged into the equations below
for a=1:numel(Scores)
if Scores(a)>=Ave+1.5*SD
A=A+1;
High=High+1;
fprintf(FID,'%d A\n',StudentID);
continue
elseif (Ave+1.5*SD>Scores(a))>=Ave+0.5*SD
B=B+1;
High=High+1;
fprintf(FID,'%d B\n',StudentID);
continue
elseif (Ave+0.5*SD>Scores(a))>=Ave-0.5*SD
C=C+1;
Average=Average+1;
fprintf(FID,'%d C\n',StudentID);
continue
elseif (Ave-0.5*SD>Scores(a))>=Ave-1.5*SD
D=D+1;
Low=Low+1;
fprintf(FID,'%d D\n',StudentID);
elseif Ave-1.5*SD>Scores(a)
F=F+1;
Low=Low+1;
fprintf(FID,'%d F\n',StudentID);
continue
end
end
The only question I have is if I have the mean and standard deviation set up the correct way to be read from the text file.

採用された回答

Star Strider
Star Strider 2021 年 3 月 10 日
I am being asked to find the average of this using the mean function and also to find the standard deviation using the std function
The current calculations are correct. That’s not the problem.
Im wondering if its doing this because I am not correctly doing mean and std or if its something entirely else?
It’s something else. Take a look at the logic in the if block statements. It will likely be necessary to do something like:
if Score(a) < Condition1 & Score(a) > Condition2
... CODE ...
for each one, to make each of them selective as appropriate.
I leave the rest to you.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by