Because there are too many parameters in the experiment, it is necessary to record the parameters and results in the experiment and save them as log files in order to compare the parameters of each experiment with the subsequent recurrence.
<span style= "font-family:arial, Helvetica, Sans-serif;" >function [] = Writelog (logfilename,varargin) </span>
Dirpath = '. \log\ ';
Addpath (Genpath (Dirpath));
FID = fopen ([Dirpath LogFileName], ' at ');
% open file, ' at ' represents the way to add at the end of the original content to write
fprintf (FID, '%s\n ', Datestr (now,0));
% with the fprintf function to write data, the DATESTR function is used to format time 0 to indicate the time format: dd-mmm-yyyy HH:MM:SS
fprintf (FID, '%s\n ', ');
% %s refers to the output as a string, \ n indicates that the output is complete after the return for
i = 1:length (varargin)
fprintf (FID, '%s ', varargin{i});
if (mod (i,2) = = 1)
fprintf (FID, '%s ', ': ');
End
if (mod (i,2) = = 0)
fprintf (FID, '%s\n ', ');
End
End
fprintf (FID, '%s\n ', ');
fprintf (FID, '%s\n ', ');
Fclose (FID);% don't forget to close the file
Invocation Example:
Writelog (' 2dcrack_running_log.txt ',...
' ---start parameters ', '---',...
' File name ', [filename '. jpg '],...
' Number of searches Itern ', num2str (itern1),...
' Start position ', [Num2str (StartRange (1)) ', ' Num2str (StartRange (2))],...
' ---results related ', '---',...
' Actual search times ', Num2str (Nnz (pconcav_2)),...
' Number of pivot points ', Num2str (Nnz (img89)),...
' Result save file name ', ['. \results\ ' filename ' _result.jpg ']);