function generateStatisticsTXT ( statistics ) 

disp('Generating Statistics Text file');

s = statistics; 

fid = fopen('stats.txt','w+');

fprintf(fid, '%4d, %6.3f, %4d, %6.3f, ', ...
        s.startWeekNum, s.startTime, s.endWeekNum, s.endTime );

fprintf(fid, 'Total, %d, ', s.epochs);
fprintf(fid, '%.3f, ', s.meanPosErr);
fprintf(fid, '%.3f, ', s.stdPosErr);
fprintf(fid, '%.3f, ', s.meanVelErr);
fprintf(fid, '%.3f, ', s.stdVelErr);

for idx = 1:length(s.posTypeBySeg)
  fprintf(fid, '%s, %d, ', s.posTypeBySeg{idx}, s.epochsBySeg(idx));
  fprintf(fid, '%.3f, ', s.meanPosErrBySeg{idx});
  fprintf(fid, '%.3f, ', s.stdPosErrBySeg{idx});
  fprintf(fid, '%.3f, ', s.meanVelErrBySeg{idx});
  fprintf(fid, '%.3f, ', s.stdVelErrBySeg{idx});
end

fprintf(fid, '\n'); 

fclose(fid); 

end