How can I save the MATLAB Command Window output to a text file?

614 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2018 年 6 月 11 日
編集済み: MathWorks Support Team 2022 年 3 月 7 日
How can I save the MATLAB command window output to a text file?

採用された回答

MathWorks Support Team
MathWorks Support Team 2022 年 3 月 7 日
編集済み: MathWorks Support Team 2022 年 3 月 7 日
The easiest way is to use the "diary" function:
It will create a log file that contains keyboard input and result output. You can also customize the name for the output file. For example, to write into "myDiaryFile", execute:
diary myDiaryFile
a = 1;
b = sin(a);
x = ones(4)
diary off
Please note that the content in the command window might not be written into the log file right away. You can force the writing by toggling the switch for "diary" function. Example code:
diary on
a = 2 % Output of this line might not be written to file right away
diary off % until this command is executed
diary on % You could put diary 'on' if you want to log more command window output
a = 3
diary off
  2 件のコメント
laurent jalabert
laurent jalabert 2021 年 12 月 22 日
編集済み: laurent jalabert 2021 年 12 月 22 日
diary is working well, however, when displaying a table, the headers are in bold characters, but the diary will generate a text file containing the html balise like <strong>Estimate</strong>
For instance, when using non linear regression fit, the mdl generates output with Estimate, SE, ... and they are displayed with the balise in the diary, which is not elegant, like this :
<strong>Estimate</strong> <strong>SE</strong> <strong>tStat</strong> <strong>pValue</strong>
<strong>___________________</strong> <strong>___________________</strong> <strong>________________</strong> <strong>____________________</strong>
Is there any way to remove the <strong> in diary text file ? Can a diary be recorded as html ?
laurent jalabert
laurent jalabert 2022 年 1 月 5 日
Sorry, I answer myself, which is not good. But my intention is to help people who may have similar problem.
When using non linear regression fit, the model mdl is displayed in the command window, with showing a table, with headers in bold characters. However, if like me, you use the command window and diary function to record the status of your running program, then the text file of the diary will display those bold character with the html code, which is not elegant. So it is possible to remove the bold character by using this function : formattedDisplayText(mdl,"SuppressMarkup",true)
section(formattedDisplayText(mdl,"SuppressMarkup",true));
function section(texte)
str_section = "*************************************";
disp(newline+ str_section + newline + texte + newline + str_section);
end
Once again, I sorry for answering my own questions, but I asked the question several weeks ago, and in between I continued my effort to find a solution, then I share it.

サインインしてコメントする。

その他の回答 (1 件)

laurent jalabert
laurent jalabert 2021 年 2 月 10 日
編集済み: laurent jalabert 2021 年 2 月 10 日
diary_name = strcat(datestr(now),'_diary.txt');
diary_folder = pwd;
diary(diary_name)
disp(datestr(now))
diary off
(I am not sure diary off will stop the currently running diary(diary_name) ...)
It will be nice to write like this :
diary(diary_folder, diary_name,'on')
diary(diary_folder,diary_name,'off')

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by