1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| PathName = uigetdir; % standard dialog box for selecting directory
d = dir(fullfile(PathName,'*.txt'));
nLines = 0;
col_max =0;
% Find number of lines
fid = fopen(fullfile(PathName,d(1).name), 'r');
while (fgets(fid) ~= -1),
nLines = nLines+1;
end
fclose(fid);
% Find the max of columes
for i=1:numel(d)
fid = fopen(fullfile(PathName,d(i).name), 'r');
pos = ftell(fid);
cols = numel(regexp(fgetl(fid), '\t'))+1;
fseek(fid, pos, 'bof');
while (cols >= col_max)
col_max = max(cols, col_max);
position = i; % retrieve the index_max
end
end
disp(['TEXT FILE NUMBER ' num2str(position) ' HAS THE MAX_SIZE:' num2str([nLines col_max])]); |
Partager