%---------------------------------------------------------
% example_multiple_files
%---------------------------------------------------------
% find all files ending in .dat
% count the number of datapoints in each file
%---------------------------------------------------------
% N.Teanby      24/2/2014	Original version
%---------------------------------------------------------
clear all
close all

% get a list of all files ending in .dat in the current directory
filelist = dir('*.dat');

% count how many files there are
nfiles   = length(filelist);

% define a blank array for the results
xfiles   = zeros(nfiles,1);

% cycle round the files
for ifile = 1:nfiles
  
  % set filename
  filename  = filelist(ifile).name;
  
  % load the file
  dat       = load(filename);
  
  % use the numel function to determine the total number of elements in the file
  % put the results in the xfiles array
  xfiles(ifile) = numel(dat);
  
end
