繁体   English   中英

如何将 MATLAB 的命令 Window 的内容保存到文件中?

[英]How to save the contents of MATLAB's Command Window to a file?

我想将“命令行窗口”中的所有内容自动保存到文件中。 有没有办法做到这一点?

您有几个选项可用于保存命令 Window 中的内容:

  • 您可以使用DIARY命令执行此操作。 您甚至可以自动执行此操作,以便它始终通过修改您的startup.m文件以打开文本日志记录来记录您所做的事情:

     diary('myTextLog.txt'); %# Text will be appended if this file already exists

    然后修改您的finish.m文件以关闭注销:

     diary('off');

    这将自动为每个 MATLAB session 存储命令 Window 的整个文本内容,这可能会变成一个相当大的文本文件。

  • 除了使用 DIARY 命令并修改您的startup.mfinish.m文件之外,另一个选项是使用-logfile选项启动 MATLAB :

     matlab -logfile "myTextLog.txt"

    虽然我不确定每次启动 MATLAB 时这是否会覆盖文本文件或 append。

  • If you're just wanting to save the output from evaluating one or more expressions, you can use the EVALC function to evaluate a string containing your expression and capture the output that would normally go to the command window in a character array. 然后,您可以使用FPRINTF将此字符数组打印到文件中。

  • 最后,如果您不想从键入的命令中保存显示的 output,而只想存储命令本身,那么命令历史记录就是您想要的。 MATLAB 自动存储一个最大大小为 200,000 字节的history.m文件,添加新条目时删除最旧的条目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM