【Matlab】利用diary记录日志/保存命令窗口输出

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014636245/article/details/84799477

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

猜你喜欢

转载自blog.csdn.net/u014636245/article/details/84799477
今日推荐