简体   繁体   English

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

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

I want to save everything in the "Command Window" to a file automatically.我想将“命令行窗口”中的所有内容自动保存到文件中。 Is there a way to do it?有没有办法做到这一点?

You have a few options available for saving content from the Command Window:您有几个选项可用于保存命令 Window 中的内容:

  • You can do this using the DIARY command.您可以使用DIARY命令执行此操作。 You could even automate this so that it always records what you do by modifying your startup.m file to turn on text logging:您甚至可以自动执行此操作,以便它始终通过修改您的startup.m文件以打开文本日志记录来记录您所做的事情:

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

    And then modify your finish.m file to turn logging off:然后修改您的finish.m文件以关闭注销:

     diary('off');

    This will automatically store the entire text content of the Command Window for every MATLAB session, which could grow into a rather large text file.这将自动为每个 MATLAB session 存储命令 Window 的整个文本内容,这可能会变成一个相当大的文本文件。

  • Another option besides using the DIARY command and modifying your startup.m and finish.m files is to start MATLAB using the -logfile option :除了使用 DIARY 命令并修改您的startup.mfinish.m文件之外,另一个选项是使用-logfile选项启动 MATLAB :

     matlab -logfile "myTextLog.txt"

    Although I'm not sure if this will overwrite the text file or append to it each time you start MATLAB.虽然我不确定每次启动 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. 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. You can then print this character array to a file using FPRINTF .然后,您可以使用FPRINTF将此字符数组打印到文件中。

  • Finally, if you're not interested in saving the displayed output from commands you type, but you instead just want to store the commands themselves, then the Command History is what you want.最后,如果您不想从键入的命令中保存显示的 output,而只想存储命令本身,那么命令历史记录就是您想要的。 MATLAB automatically stores a history.m file with a maximum size of 200,000 bytes, deleting the oldest entries when newer ones are added. MATLAB 自动存储一个最大大小为 200,000 字节的history.m文件,添加新条目时删除最旧的条目。

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

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