How can I write a result that is calculted by current code as a comment to the same script?

3 ビュー (過去 30 日間)
Hi,
I have a code that generates a result like "a is an odd number" after executing the program. I want to show the last result inside the current code as a comment before run the program again. For example, I have runned the program today and it generated "a is a odd number". I want to see the last result when I want to run the code again tomorrow. How can I do this?
  2 件のコメント
darova
darova 2020 年 3 月 27 日
Can't you save result in a separate file?
save result
Mehmet Türker TAKCI
Mehmet Türker TAKCI 2020 年 3 月 27 日
The problem is not saving results. The problem is saving the result as a comment at the beginning of the codes in the script.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 27 日
I am not sure why would you want to do that. Anyway, this will show how to add a string as a comment to the end of current script file
result = sprintf('a is an odd number'); % generate a string through your code
filename = mfilename;
f = fopen([filename '.m'], 'a');
fprintf(f, '\n%s', ['% ' result]);
fclose(f);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by