【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

  • 5
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值