matlab 中可以利用diary函數記錄下命令行窗口的輸出到指定文件中,方便后期檢查調試和運行信息。
diary
diary
是matlab中的日志工具,可以將Command Window 中的內容保存到文件中去。使用方法:
在命令行中輸出:
diary 'path/yourlogfile.txt'
對應的的文件將會保存在path
路徑下的yourlogfile.txt
文件里。
同時,可以使用:
diary off,diary on
命令來關閉、打開日志。
%diary使用例子
>> diary 'mylog.txt' %打開日志記錄命令窗口
>> disp('add this into mylog')
add this into mylog
>> 1+1
ans =
2
>> diary off %關閉了日志,不再記錄
>> disp('this will not log')
this will not log
>> diary on %重新打開日志記錄
>> disp('this will be log')
this will be log
>> disp('this will be log')
this will be log
>> diary off %關閉,保存記錄
在mylog.txt文件中就可一看到打開日志的幾段命令和輸出:
注意:結束時,需要利用diary off命令來結束日志,以便關閉文件保存日志。