[英]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.m
和finish.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.