开发者

printing text into a file in Matlab

开发者 https://www.devze.com 2023-02-18 01:48 出处:网络
I want to log the running of my program, specifically the running time of 开发者_Python百科each part. At this moment I print to the screen using disp. Is there a way so that some of the things I print

I want to log the running of my program, specifically the running time of 开发者_Python百科each part. At this moment I print to the screen using disp. Is there a way so that some of the things I print would also be printed into a text file?


You can use the DIARY command, that captures everything from the command window.


There are other solutions to this problem where you write to one or more logfiles opened when your program is running. This provides a permanent record without polluting your work space or diary. It also works well if you compile your MATLAB application.

Jan Simon has a nice solution at MATLAB Central which uses a persistant file id so the log to file mechanism can be used again and again throughout an application with many functions without passing the file id about.

Others at MATLAB Central (here and here) have developed class based solutions with more features.


Also, fprintf.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号