export
Description
path = export(
converts the specified
live script or function to a PDF file with the same name and returns the full path to the
converted file. file
)export
saves the converted file to the current folder.
By default, export
uses the values specified by the matlab.editor Settings when creating the converted file.
path = export(
specifies the file name and location for the converted file. If
file
,outputfile
)outputfile
includes a file extension, the export function converts
the live script or function to that format.
path = export(___,
specifies options for customizing the converted file by using one or more name-value
arguments in addition to the input argument combinations in previous syntaxes. For example,
you can convert the specified file to a Microsoft® Word document instead of a PDF file, specify whether to hide code, or adjust the
paper size and page orientation of the converted file. Name=Value
)
Examples
Export Live Script to PDF File
Convert a live script to a PDF file including the code, output, and formatted text, and save it in the current folder.
export("myscript.mlx")
ans = 'C:\myFiles\myscript.pdf'
Export Live Script to Microsoft Word Document
Convert a live script to a Microsoft Word document including the code, output, and formatted text.
wordfile = export("myscripts\myscript.mlx","myconvertedfiles\livescripts\myscript.docx")
wordfile = 'C:\myMATLABFiles\myconvertedfiles\livescripts\myscript.docx'
Customize Converted File
Use name-value arguments to hide the code and change the page size and orientation of the converted file.
wordfile = export("myscript.mlx","C:\Work\myfiles\myscript.docx", ... HideCode=true,PageSize="A4",Orientation="Landscape")
wordfile = 'C:\Work\myfiles\myscript.docx'
Input Arguments
file
— Name of live script or function to convert
character vector | string scalar
Name of live script or function to convert, specified as a character vector or
string scalar. Specify file
as an absolute or relative path. If
file
is not on the MATLAB® path, include the .mlx
extension.
outputfile
— Name of converted file
character vector | string scalar
Name of converted file, specified as a character vector or string scalar. Specify
outputfile
as an absolute or relative path. The destination
folder specified by outputfile
must exist and be writable.
export
uses the file extension of
outputfile
to determine the format of the converted file. For
example, if outputfile
has a .docx
extension,
export
converts the live script or function to a Microsoft Word document.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: path =
export("myfiles/mylivescript.mlx",Format="docx")
Format
— Output format
"pdf"
(default) | "html"
| "docx"
| "latex"
| "m"
Output format, specified as one of the values listed in the table.
Value | Output Format | Default File Extension |
---|---|---|
"pdf" (default) | Portable Document Format (PDF) | .pdf |
"html" | Hypertext Markup Language | .html |
"docx" | Microsoft Word document | .docx |
"latex" | LaTeX | .tex |
"m" | MATLAB code file | .m |
Format
takes precedence over the format specified
by outputfile
. If outputfile
does not
include a file extension, export
uses the default file extension
for the specified Format
.
When exporting to LaTeX, MATLAB creates a separate matlab.sty
file in the same folder
as the output document, if one does not exist already. STY files, also known as LaTeX
Style Documents, give you more control over the appearance of the output
document.
Example: path = export("myfiles/mylivescript.mlx","myfiles/outfile.xml",
Format="html")
creates an HTML file with a .xml
extension.
OpenExportedFile
— Whether to open converted file
false
or 0
(default) | true
or 1
Whether to open the converted file after creating it, specified as a numeric or
logical 1
(true
) or 0
(false
).
Example: path =
export("myfiles/mylivescript.mlx",OpenExportedFile=true)
Run
— Whether to run code
true
or 1
(default) | false
or 0
Whether to run the code and include the output in the converted file, specified as
a numeric or logical 1
(true
) or
0
(false
).
Example: path =
export("myfiles/mylivescript.mlx",Run=false)
CatchError
— Whether to catch errors
true
or 1
(default) | false
or 0
Whether to catch errors when running the live script or function during
conversion, specified as a numeric or logical 1
(true
) or 0
(false
). If
true
and an error occurs, export
includes
the error in the converted file. If false
and an error occurs,
export
displays the error in the Command Window and does not
create a converted file.
Example: path =
export("myfiles/mylivescript.mlx",CatchError=false)
HideCode
— Whether to hide the code
true
or 1
| false
or 0
Whether to hide the code, specified as a numeric or logical 1
(true
) or 0
(false
). If
true
, the code in the live script or function is hidden (not
included) in the converted file. If false
, the code is included. If
this option is not specified, export
uses the current saved state
of the live script or function to determine whether to hide the code in the converted
file. For example, if the specified live script or function was last saved with the
code hidden, then the code is also hidden in the converted file.
Example: path =
export("myfiles/mylivescript.mlx",HideCode=false)
PageSize
— Page size
"Letter"
| "Legal"
| "Tabloid"
| "A2"
| "A3"
| "A4"
| "A5"
Page size of the converted file, specified as one of the standard paper type values in this table.
Value | Paper Size (Width x Height) |
---|---|
| 8.5-by-11 in (default in US) |
| 8.5-by-14 in |
| 11-by-17 in |
| 42-by-59.4 cm |
| 29.7-by-42 cm |
| 21-by-29.7 cm (default in Europe and Asia) |
| 14.8-by-21 cm |
This option is available only when the converted file is a Microsoft Word document, PDF file, or LaTeX file.
Example: path =
export("myfiles/mylivescript.mlx",PageSize="Legal")
Orientation
— Page orientation
"Portrait"
(default) | "Landscape"
Page orientation of the converted file, specified as "Portrait"
or "Landscape"
.
This option is available only when the converted file is a Microsoft Word document, PDF file, or LaTeX file.
Example: path =
export("myfiles/mylivescript.mlx",Orientation="Landscape")
Margins
— Document margins
[72 72 72 72]
(default) | 1-by-4 vector
Document margins of the converted file, specified as a 1-by-4 vector of margin
values with the format [left
top
right
bottom
]. Each margin value is specified in points as a
positive integer between 0 and 255. A value of 72 points is equivalent to 1 inch or
2.54 cm.
This option is available only when the converted file is a Microsoft Word document, PDF file, or LaTeX file.
Example: path = export("myfiles/mylivescript.mlx",Margins=[25 72 72
25])
FigureFormat
— Figure format
"png"
| "jpeg"
| "bmp"
| "svg"
| "eps"
| "pdf"
Figure format of output figures in the converted file, specified as
"png"
, "jpeg"
, "bmp"
,
"svg"
, "eps"
, or "pdf"
. By
default, the value of this name-value argument is "png"
for PDF
files and "eps"
for LaTeX files.
This option is available only when the converted file is a PDF file or a LaTeX
file. In addition, the Run
name-value argument must be
true
(default value) for this option to have an effect.
Example: path =
export("myfiles/mylivescript.mlx",FigureFormat="jpeg")
FigureResolution
— Figure resolution
600
(default) | positive integer
Figure resolution of output figures in the converted file, specified in DPI as a positive integer between 36 and 2880.
This option is available only when the converted file is a PDF file or a LaTeX
file. In addition, the Run
name-value argument must be
true
(default value) for this option to have an effect.
Example: path =
export("myfiles/mylivescript.mlx",FigureFormat=800)
Version History
Introduced in R2022a
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)