Create run log history each time code is run

조회 수: 5 (최근 30일)
Jonathan Greenwood
Jonathan Greenwood 2019년 7월 18일
답변: Abhilash Padma 2019년 7월 30일
I have a code that I am running and wish to write a text file with time and date and name of the input file i have used every time the code is run.
I have struggled to this in a form in which can be added to each time it is run.
Any help would be appreciated, thanks
  댓글 수: 1
Joel Handy
Joel Handy 2019년 7월 18일
So you want a single log file and each time you run your code you want to append that info to the file. You dont want a new file each time you run.
Are you having trouble figuring out how write to a file or are you just looking for the 'a+' permissions option of the fopen command? That willlet you append lines to the end of an existing file.

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

답변 (1개)

Abhilash Padma
Abhilash Padma 2019년 7월 30일
I assume that you want to append the execution information (time, date and name of the input file) of your code each time whenever you execute it in a single file. Following is the sample code to be added in your source code which may serve your purpose.
fid=fopen('log.txt','a+');
time = datestr(clock,'YYYY/mm/dd HH:MM:SS:FFF');
inputFile='example';
fprintf(fid,'\n%s %s',time,inputFile);
fclose(fid);

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by