フィルターのクリア

How do I find the maximum average score for this code in my loop

2 ビュー (過去 30 日間)
Lauren Harkness
Lauren Harkness 2017 年 10 月 13 日
回答済み: Aveek Podder 2017 年 10 月 17 日
I have this code below, when i run this it displays the line number (count) and the average score, how do i find the max of these average scores that it outputs/do I need to put the max function inside or outside of the while loop, and also output the count/line that corresponds with the max average?
fh = fopen(txt,'r');
filename = txt;
line = fgetl(fh);
count = 1
while ischar(line)
[names,scores]= strtok(line, ':');
scores = scores(2:end);
numArray=str2num(scores);
tot = sum(numArray);
avg = tot/(length(numArray));
line = fgetl(fh);
disp(count);
disp(avg);
count = count + 1;
end

回答 (1 件)

Aveek Podder
Aveek Podder 2017 年 10 月 17 日
Hi, You can store the average values in an array and use 'max' function outside the loop to get the maximum Value and indices.
For more information on 'max' function please go through the following link:

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by