For loop data placement

num_games=31;
% file available
if ~exist( 'WBB_stats_2019.txt', 'file' )
fprintf( 'File not found\n' )
else
% file avaialable continue
disp(' 2018-19 Auburn WBB Results')
fprintf(' Scores Current Ave Pts')
fprintf('\n')
disp(' Date AU - Opp W/L AU Opp')
[dates(:,1),dates(:,2),dates(:,3),scores(:,6),scores(:,7)]=textread('WBB_stats_2019.txt','%f %f %f %*s %*s %f %f');
date_scores=[dates,scores(:,6),scores(:,7)];
fprintf('%02.0f/%02.0f/%04.0f %02.0f - %02.0f\n',date_scores.');
for g=1:num_games
if scores(g,6) > scores(g,7)
disp('W');
else
disp('L')
end
end
end
My code is putting the win/loss letter (W or L) under the Date column instead of to the right of the score. I need the W or L to go under W/L column header.
2018-19 Auburn WBB Results
Scores Current Ave Pts
Date AU - Opp W/L AU Opp
11/06/2018 97 - 48
11/09/2018 80 - 59
11/11/2018 79 - 76
11/13/2018 64 - 67
11/25/2018 71 - 59
11/28/2018 77 - 58
12/02/2018 95 - 79
12/06/2018 81 - 70
12/16/2018 73 - 46
12/18/2018 84 - 78
12/20/2018 86 - 81
12/22/2018 96 - 44
12/29/2018 83 - 50
01/03/2019 69 - 78
01/06/2019 64 - 56
01/10/2019 66 - 56
01/14/2019 59 - 85
01/17/2019 72 - 70
01/24/2019 67 - 69
01/27/2019 65 - 74
01/31/2019 64 - 51
02/03/2019 59 - 58
02/07/2019 68 - 78
02/10/2019 75 - 72
02/14/2019 62 - 73
02/17/2019 77 - 38
02/24/2019 58 - 54
02/28/2019 66 - 73
03/03/2019 56 - 46
03/07/2019 53 - 52
03/08/2019 62 - 64
W
W
W
L
W
W
W
W
W
W
W
W
W
L
W
W
L
W
L
L
W
W
L
W
L
W
W
L
W
L

Answers (1)

Put the fprintf inside the loop, so
for g=1:num_games
if scores(g,6) > scores(g,7)
result = 'W';
else
result = 'L'
end
fprintf('%02.0f/%02.0f/%04.0f %s %02.0f - %02.0f\n',...
date_scores(g, 1), date_scores(g, 2), date_scores(g, 3), result, date_scores(g, 4), date_scores(g, 5) );
end
or something like that (I haven't tested this because you forgot to attach 'WBB_stats_2019.txt').

Asked:

on 4 Apr 2019

Answered:

on 5 Apr 2019

Community Treasure Hunt

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

Start Hunting!