Create a file that has some college department names and enrollments. For example, it might look like this:
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:28.9
All Answers
total answers (1)
Ch9Ex28.m
% Read in department names and enrollments from one file and
% write first 4 chars of names w enrollments to another file
fid = fopen('eng.dat');
if fid == -1
disp('File open not successful')
else
%Open a new file for writing
nfid = fopen('neweng.dat','w');
while feof(fid) == 0
aline = fgetl(fid);
%Seprate department names and enrollment
[dep num] = strtok(aline);
num = str2num(num);
fprintf(nfid,'%s %d\n',dep(1:4),num); %Write to file
end
%Error-check file close
closeresult = fclose('all');
if closeresult == 0
disp('File close successful')
else
disp('File close not successful')
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer