How can I print an MATLAB file programmatically?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuesta aceptada
MathWorks Support Team
el 29 de Jun. de 2009
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Report Generator en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!