clear;
filename = 'measurement.dat';
rows = 4;
cols = 4;

% Open the file for reading
datafile = fopen(filename); % default is open as read-only
%Equivalent to fopen(filename,'r');

% Read the header, skipping the title
headerFormat = '%*s %*s\nN=%d\n\n';
N = fscanf(datafile, headerFormat, 1);
disp(N)

% Read the data and do something with it
for n = 1 : N % for each set of data values

    % Read the time
    time = fscanf(datafile, '%s\n', 1);

    % Read the date
    date = fscanf(datafile, '%s\n', 1);

    % Read the measurement values
    % Note need to give columns first, then rows in fscanf and need to
    % transpose the matrix read in to get it into the same format as
    % the data in the file
    values = fscanf(datafile, '%f', [cols, rows]);
    values = values';

    % Do something with the data read in
    disp([date ' ' time ': ']);
    disp(values);
    disp(['Mean = ' num2str(mean(values))]);   % mean of each column
    disp(['Std dev = ' num2str(std(values))]); % std dev of each column
    disp(' '); % force blank line between data sets
end

% Close the datafile
fclose(datafile);