Main Content

export

Convert live script or function to standard format

    Description

    example

    path = export(file)converts the specified live script or function to a PDF file with the same name and returns the full path to the converted file.exportsaves the converted file to the current folder. By default,exportuses the values specified by thematlab.editor Settingswhen creating the converted file.

    example

    path = export(file,outputfile)specifies the file name and location for the converted file. Ifoutputfile包括文件扩展名,the export function converts the live script or function to that format.

    example

    path = export(___,Name=Value)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 aMicrosoft®Worddocument instead of a PDF file, specify whether to hide code, or adjust the paper size and page orientation of the converted file.

    Examples

    collapse all

    住脚本转换为PDF文件包括code, output, and formatted text, and save it in the current folder.

    export("myscript.mlx")
    ans = 'C:\myFiles\myscript.pdf'

    Convert a live script to aMicrosoft Worddocument including the code, output, and formatted text.

    wordfile = export("myscripts\myscript.mlx","myconvertedfiles\livescripts\myscript.docx")
    wordfile = 'C:\myMATLABFiles\myconvertedfiles\livescripts\myscript.docx'

    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

    collapse all

    Name of live script or function to convert, specified as a character vector or string scalar. Specifyfileas an absolute or relative path. Iffileis not on the MATLAB®path, include the.mlxextension.

    Name of converted file, specified as a character vector or string scalar. Specifyoutputfileas an absolute or relative path. The destination folder specified byoutputfilemust exist and be writable.

    exportuses the file extension ofoutputfileto determine the format of the converted file. For example, ifoutputfilehas a.docxextension,exportconverts the live script or function to aMicrosoft Worddocument.

    Name-Value Arguments

    Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis 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")

    Output Options

    collapse all

    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 Worddocument .docx
    "latex" LaTeX .tex
    "m" MATLAB code file .m

    Formattakes precedence over the format specified byoutputfile. Ifoutputfiledoes not include a file extension,exportuses the default file extension for the specifiedFormat.

    When exporting to LaTeX, MATLAB creates a separatematlab.styfile 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.xmlextension.

    Whether to open the converted file after creating it, specified as a numeric or logical1(true) or0(false).

    Example:path = export("myfiles/mylivescript.mlx",OpenExportedFile=true)

    Code Options

    collapse all

    Whether to run the code and include the output in the converted file, specified as a numeric or logical1(true) or0(false).

    Example:path = export("myfiles/mylivescript.mlx",Run=false)

    Whether to catch errors when running the live script or function during conversion, specified as a numeric or logical1(true) or0(false). Iftrueand an error occurs,exportincludes the error in the converted file. Iffalseand an error occurs,exportdisplays the error in the Command Window and does not create a converted file.

    Example:path = export("myfiles/mylivescript.mlx",CatchError=false)

    Whether to hide the code, specified as a numeric or logical1(true) or0(false). Iftrue, the code in the live script or function is hidden (not included) in the converted file. Iffalse, the code is included. If this option is not specified,exportuses 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)

    Page size of the converted file, specified as one of the standard paper type values in this table.

    Value

    Paper Size (Width x Height)

    "Letter'

    8.5-by-11 in (default in US)

    "Legal"

    8.5-by-14 in

    "Tabloid"

    11-by-17 in

    "A2"

    42-by-59.4 cm

    "A3"

    29.7-by-42 cm

    "A4"

    21-by-29.7 cm (default in Europe and Asia)

    "A5"

    14.8-by-21 cm

    This option is available only when the converted file is aMicrosoft Worddocument, PDF file, or LaTeX file.

    Example:path = export("myfiles/mylivescript.mlx",PageSize="Legal")

    Page orientation of the converted file, specified as"Portrait"or"Landscape".

    This option is available only when the converted file is aMicrosoft Worddocument, PDF file, or LaTeX file.

    Example:path = export("myfiles/mylivescript.mlx",Orientation="Landscape")

    Document margins of the converted file, specified as a 1-by-4 vector of margin values with the format [lefttoprightbottom]. 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 aMicrosoft Worddocument, PDF file, or LaTeX file.

    Example:path = export("myfiles/mylivescript.mlx",Margins=[25 72 72 25])

    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, theRunname-value argument must betrue(default value) for this option to have an effect.

    Example:path = export("myfiles/mylivescript.mlx",FigureFormat="jpeg")

    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, theRunname-value argument must betrue(default value) for this option to have an effect.

    Example:path = export("myfiles/mylivescript.mlx",FigureFormat=800)

    Version History

    Introduced in R2022a