To publish your code:
Create a matlab script or function. Divide the code into steps or sections by inserting two percent signs ( %% ) at the beginning of each section.
Document the code by adding explanatory comments at the beginning of the file and within each section. ...
Publish the code. On the Publish tab, click Publish.
Syntax:
publish(file)
example
publish(file,format)
publish(file,Name,Value)
publish(file,options)
By default, matlab creates a subfolder named html, which contains an HTML file and files for each graphic that your code creates. The HTML file includes the code, formatted comments, and output. Alternatively, you can publish to other formats, such as PDF files or Microsoft® PowerPoint® presentations.
publish(file) generates a view of a matlab® file in HTML format for sharing your code. For example, publish('myfile.m') executes the code in myfile.m using the base workspace and saves the formatted code and results in /html/myfile.html. The html subfolder is relative to the file folder.
When matlab publishes a file, it can delete existing files from the output folder that start with the same name as file.
Output format of published matlab file, specified as one of the following string values
Output Format |
String Value |
Hypertext Markup Language |
'html' (default) |
Microsoft Word |
'doc' |
LaTeX |
'latex' |
Microsoft PowerPoint® |
'ppt' |
Extensible Markup Language |
'xml' |
Portable Document Format |
'pdf' |
matlab enables you to include an inline LaTeX expression in any code that you intend to publish. To insert an inline expression, surround your LaTeX markup with dollar sign characters ($). The $ must immediately precede the first word of the inline expression, and immediately follow the last word of the inline expression, without any space in between.
matlab publishing supports standard LaTeX math mode directives. Text
mode directives or directives that require additional packages are not
supported.
To use LaTeX Equations:
%% Inline Expression
% This is an equation: $x^2+e^{\pi i}$. It is
% inline with the text.
If you publish the sample text markup to HTML, this is the resulting output.
LaTeX Display Equation
matlab enables you to insert LaTeX symbols in blocks that are offset from the main comment text. Two dollar sign characters ($$) on each side of an equation denote a block LaTeX equation. Publishing equations in separate blocks requires a blank line in between blocks.
This code is a sample text markup.
%% LaTeX Equation Example
%
% This is an equation:
%
% $$e^{\pi i} + 1 = 0$$
%
% It is not in line with the text.
If you publish to HTML, the expression appears as shown here.