Why is this fprintf not wprking correctly?
조회 수: 1 (최근 30일)
이전 댓글 표시
studentNames = ["Amy", "Flynn", "Barbara", "George", "Jonathan", "Isaac", "Cindy", "Hank", "Elaine", "Debbie"];
Test1 = [79, 71, 98, 68, 65, 97, 72, 68, 68, 82];
Test2 = [61, 94, 98, 66, 91, 90, 76, 86, 67, 88];
Final = [68, 84, 85, 90, 91, 85, 88, 80, 51, 72];
fileID = fopen('Students.txt','w');
%% A.
for i = 1: length(studentNames)
Avg1 = Test1 * .3;
Avg2 = Test2 * .3;
Avg3 = Final * .4;
TotalAvg = Avg1 + Avg2 + Avg3;
end
fprintf(fileID, '%s has an average of %g \r\n', studentNames,TotalAvg);
댓글 수: 2
답변 (2개)
Daniel M
2019년 10월 28일
array = [studentNames;string(TotalAvg)];
fprintf('%s has an avg of %g\r\n',array);
댓글 수: 0
Walter Roberson
2019년 10월 28일
You are already using string objects so you might as well use compose() to format the text, possibly fwrite() the results
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!