MATLAB Write txt save log

Source: Internet
Author: User
Tags save file time 0


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 ']);





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.