Creating log of matlab run script with time and date

6 次查看(过去 30 天)
i want to create log file with date and time. could you please help me how to write time and date information into log file.

采纳的回答

Jan
Jan 2018-6-4
FileName = fullfile(tempdir, 'MyLogFile.txt');
Message = 'Hello';
fid = fopen(FileName, 'a');
if fid == -1
error('Cannot open file: %s', FileName);
end
fprintf(fid, '%s: %s', datestr(now, 0), Message);
fclose(fid);
See doc datestr for other formats.
With a modern Matlab version:
fprintf(fid, '%s: %s', datetime, Message);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by