MATLAB: How to create a log file

log file

Dear Matlab expert, Anyone of you know how to create a log file?
Your sincerely, Kelly

Best Answer

It depends on what you consider a "log file" to be.
It is easy to append any messages to a file:
yourMsg = 'I am alive.'
fid = fopen(fullfile(tempdir, 'YourLogFile.txt'), 'a');
if fid == -1
error('Cannot open log file.');
end
fprintf(fid, '%s: %s\n', datestr(now, 0), yourMsg);
fclose(fid);
Copy this into a function and you can use it from where ever you want.
Or perhaops you mean the diary function? See:
doc diary