clear;
filename = 'measurement.dat';
title = 'Measurement Data';
N = 3;
rows = 4;
cols = 4;

% Open file for writing
datafile = fopen(filename, 'w');

% Write the heading
fprintf(datafile, '%s\n', title);
fprintf(datafile, 'N=%d\n\n', N);

% Write the main data

for n = 1 : N   % for each set of data values

    % Get current date & time and convert to character strings
    % now gets the current time (as a floating point number)
    currentDateTime = now;
    % datestr converts that floating point time
    % to the chosen time format
    currDate = datestr(currentDateTime, 'dd-mmm-yyyy');
    currTime = datestr(currentDateTime, 'HH:MM:SS');

    % Write the date and time to the file
    fprintf(datafile, '%s\n%s\n', currTime, currDate);


    % Write (random) measurment values to the file
    % rand(rows, cols) gives a matrix of size [rows,cols]
    % of uniformly distributed numbers between 0 and 1
    data = rand(rows, cols);

    for r = 1 : rows
        for c = 1 : cols
            fprintf(datafile, '%f ', data(r, c));
        end
        fprintf(datafile, '\n');
    end
end

% Close the NEW data file
fclose(datafile);