| MATLAB Function Reference | ![]() |
As an alternative to the publish function, use the File > Publish filename menu or File > Publish Configuration for filename items in the Editor.
publish('script')
publish('script','format')
publish('script', options)
publish('function', options)
publish('script') runs the M-file script named script in the base workspace one cell at a time, and saves the code, comments, and results to an HTML output file. The output file is named script.html and is stored, along with other supporting output files, in an html subdirectory in script's directory.
publish('script','format') runs the M-file script named script, one cell at a time in the base workspace, and publishes the code, comments, and results to an output file using the specified format. Allowable values for format are html (the default), xml, latex for LaTeX, doc for Microsoft® Word documents, and ppt for Microsoft® PowerPoint® documents. The output file is named script.format and is stored, along with other supporting output files, in an html subdirectory in script's directory. The doc format requires the Word application, and the ppt format requires PowerPoint® application. When publishing to HTML, the M-file code is included at the end of published HTML file as comments, even when the showCode option is set to false. Because it is included as comments, it does not display in a Web browser. Use the grabcode function to extract the code from the HTML file.
publish('script', options) publishes using the structure options, which can contain any of the fields and corresponding value for each field as shown in Options for publish. Create and save structures for the options you use regularly. For details about the values, see Specify Values for the Publish Settings Property Table in the online documentation for MATLAB® software.
publish('function', options) publishes an M-file function using the structure options. The codeToEvaluate field must specify the function input and the file to publish if you set the evalCode field to true. If you set the evalCode field to false, it essentially saves the M-file to another format, such as HTML, which allows display with formatting in a Web browser.
Options for publish
Field | Allowable Values |
|---|---|
'doc','html' (default), 'latex', 'ppt', 'xml' | |
'' (default), XSL file name (used only when format is html, latex, or xml) | |
'' (default, a subfolder named html), full path | |
'png' (default unless format is latex), 'epsc2' (default when format is latex), any format supported by print when figureSnapMethod is print, any format supported by imwrite functions when figureSnapMethod is getframe. | |
'print' (default),'getframe' | |
true (default), false | |
[] (default), any positive integer specifying the maximum height, in pixels, for an image that publish.m generates | |
[] (default), any positive integer specifying the maximum width, in pixels, for an image that publish.m generates | |
true (default), false | |
true (default), false | |
true (default, continues publishing and includes the error in the published file), false (displays the error and publishing ends) | |
codeToEvaluate | m-file you are publishing (default), any valid code |
true (default), false | |
maxOutputLines | Inf (default), nonnegative integer specifying the maximum number of output lines to publish per M-file cell before truncating the output |
To publish the M-file script d:/mymfiles/sine_wave.m to HTML, run
publish('d:/mymfiles/sine_wave.m', 'html')
MATLAB runs the file and saves the code, comments, and results to d:/mymfiles/html/sine_wave.html. Open that file in the Web browser to view the published report.
This example defines the structure options_doc_nocode, publishes sine_wave.m using the defined options, and displays the resulting report. The resulting report is a Word document, d:/nocode_output/sine_wave.doc and includes results, but not MATLAB code.
options_doc_nocode.format='doc'
options_doc_nocode.outputDir='d:/nocode_output'
options_doc_nocode.showCode=false
publish('d:/mymfiles/sine_wave.m',options_doc_nocode)
winopen('d:/nocode_output/sine_wave.doc')
This examples defines the structure function_options which specifies the value of the input argument to the function, publishes the function d:/collatz.m, and displays the resulting report, an HTML document, d:/html/collatz.html
function_options.format='html';
function_options.evalCode=true;
function_options.codeToEvaluate=[ ...
'n=3' char(10) ...
'collatz(3)' char(10) ...
]
function_options.showCode=true;
publish('I:/keep_m_files/collatz.m',function_options);
web('I:/keep_m_files/html/collatz.html')This example defines the structure function_options, publishes the function d:/collatzplot.m, and displays the resulting report, an HTML document, d:/html/collatzplot.html.
function_options.format='html'
function_options.evalCode=false
publish('d:/collatzplot.m',function_options)
web('d:/html/collatzplot.html')grabcode, notebook, web, winopen
MATLAB Desktop Tools and Development Environment documentation, specifically:
![]() | psi | PutCharArray | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |