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

 채택된 답변

Jan
Jan 2016년 10월 8일

2 개 추천

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

Kelly Wong
Kelly Wong 2016년 10월 8일
Hi thanks for fast reply, i want to do something like this http://www.blackbeltcoder.com/Articles/files/a-convenient-logfile-class/LogFileSample.jpg. Is it possible to do in matlab?
Cheers, Kelly
Liz Martinez Marrero
Liz Martinez Marrero 2018년 9월 4일
Hi, The code works for the first log, but then it overwrites the previous logs. Any suggestion? Thanks
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2016년 10월 8일

댓글:

2018년 9월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by