How can I programatically print out the contents of the MATLAB Command Window?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Sep 2016
Answered: MathWorks Support Team
on 27 Sep 2016
The contents of MATLAB's Command Window can be printed out by using 'Ctrl + P' or right-clicking and selecting "Print..." from the Command Window itself. How can I do the same programmatically, such as from within scripts?
Accepted Answer
MathWorks Support Team
on 27 Sep 2016
This functionality can be emulated by using the "diary" and "system" commands. First, use "diary" to enable Command Window logging and save it in a file:
>> diary('commandLog')
>> diary on
This creates a file named 'commandLog' in MATLAB's current folder. Now, execute the commands of interest. Be sure to not suppress the output of variables with semicolons if you would like them to be written to the file. Once you are ready to print the file, execute the following commands to turn off diary logging, print the text file through Notepad, and then delete the file:
>> diary off
>> system('notepad /p commandLog')
>> delete('commandLog')
It is recommended that the file be deleted every time this workaround is used since "diary" appends Command Window text to the file if it already exists.
0 Comments
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!