How can I print an MATLAB file programmatically?

21 次查看(过去 30 天)
The File -> Print option in the MATLAB editor allows me to print the currently open file. I want to be able to print a file from within a MATLAB script or function.

采纳的回答

MathWorks Support Team
The ability to programmatically print MATLAB files is not available in MATLAB.
To work around this issue, create a COM server running Microsoft Word in MATLAB, open the respective file in Word, and then call a VBA macro that prints the file to the installed printer. The macro inserts the current date and time, the name of the MATLAB file, and the Page number into the header of the Word document that prints out.
To use the workaround, complete the following steps:
1. Download the attached files -
InsertHeaderMacro.txt
print_m_file.m
2. Define a new macro in Word by navigating to Tools-> Macro -> Record New Macro. In the 'Macro Name' box, type the name 'add_my_header'. Copy and paste the entire macro from 'InsertHeaderMacro.txt'.
3. Run the file 'print_m_file.m' with the name of the MATLAB file that you want to print as an argument in the form of a string. For example, execute the following command in the MATLAB command window:
print_m_file('myMfile.m')
where myMfile.m is to be replaced by the name of your MATLAB file.
The workaround is tested for Word 2003 and MATLAB 7.6 (R2008a).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by