【Matlab】利用diary記錄日志/保存命令窗口輸出


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命令來結束日志,以便關閉文件保存日志。



pic from pixels.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM