How to create a log file?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kelly Wong
am 8 Okt. 2016
Kommentiert: David Connell
am 5 Sep. 2018
Dear Matlab expert, Anyone of you know how to create a log file?
Your sincerely, Kelly
0 Kommentare
Akzeptierte Antwort
Jan
am 8 Okt. 2016
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
3 Kommentare
Liz Martinez Marrero
am 4 Sep. 2018
Hi, The code works for the first log, but then it overwrites the previous logs. Any suggestion? Thanks
David Connell
am 5 Sep. 2018
Liz, are you using the 'a' option with fopen?
fid=fopen(filename, 'w')
will write over the old file but
fid=fopen(filename, 'a')
will append the new data to the end of the file.
If that's not the problem could you show your relevant code?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!