Students from a class took an exam for which there were 2
versions, marked either A or B on the front cover ( ½ of the students
had version A, ½ Version B). The exam results are stored in a file
called “exams.dat”, which has on each line the version of the exam
(the letter ‘A’ or ‘B’) followed by a space followed by the integer exam
grade. Write a script that will read this information from the file using
fscanf, and separate the exam scores into two separate vectors: one
for Version A, and one for Version B. Then, the grades from the vectors
will be printed in the following format (using disp).
A exam grades:
99 80 76
B exam grades:
85 82 100
Note: no loops or selection statements are necessary!
Ch9Ex20.m
fid = fopen('exams.dat');
mat = fscanf(fid,'%c %d\n', [2 inf]);
av = char(mat(1,:)) == 'A';
as = mat(2,av);
bs = mat(2,~av);
disp('A exam grades:')
disp(as)
disp('B exam grades:')
disp(bs)
check = fclose(fid);
need an explanation for this answer? contact us directly to get an explanation for this answer