Q:

A set of data files named “exfile1.dat”, “exfile2.dat”, etc. has been created by a series of experiments. It is not known exactly how many there are, but the files are numbered sequentially with integers beginning with 1

0

A set of data files named “exfile1.dat”, “exfile2.dat”, etc. has been created by a series of experiments. It is not known exactly how many there are, but the files are numbered sequentially with integers beginning with 1. The files all store combinations of numbers and characters, and are not in the same format. Write a script that will count how many lines total are in the files. Note that you do not have to process the data in the files in any way; just count the number of lines. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch9Ex11.m

sumlines = 0;

i = 1;

filename = 'exfile1.dat';

fid = fopen(filename);

while fid ~= -1

 while ~feof(fid)

 aline = fgetl(fid);

 sumlines = sumlines + 1;

 end

 i = i + 1;

 filename = sprintf('exfile%d.dat', i);

 fid = fopen(filename);

end

fprintf('There were %d lines in the files\n', sumlines)

fclose('all');

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now