Main Content

openExample

Open a MathWorks example

    Description

    example

    openExample(examplename) downloads the specified example into a subfolder of the current running release Examples folder and then opens it. If a copy of the example exists, openExample opens the existing version of the example. If the specified example contains a project, openExample always downloads a new copy of the example, without overwriting previous versions of the example.

    example

    openExample(sfile) downloads the specified supporting file and the example it supports, and then opens the supporting file. If the specified supporting file name is included in multiple examples, openExample selects one of the examples to download.

    example

    openExample(___,Name,Value) specifies options using one or more name-value arguments in addition to the input argument in previous syntaxes. For example, to download the example to the folder C:\Work\myfiles, set the workDir argument to "C:\Work\myfiles".

    Examples

    collapse all

    Open the Create 2-D Line Plot example that is part of the MATLAB® graphics documentation.

    openExample("graphics/Create2DLinePlotsExample")

    Open the parabola.m supporting file. If parabola.m is included in multiple examples, openExample selects one of the examples to download.

    openExample("parabola.m")

    Download the MATLAB Analyze Text Data with String Arrays example to the folder C:\Work\myfiles, and open the sonnets.txt supporting file for that example.

    Use the supportingFile name-value argument instead of the sfile input argument when the supporting file to open is included in multiple examples or when it has an extension that is not supported by the sfile input argument.

    openExample("matlab/AnalyzeTextDataExample","supportingFile","sonnets.txt", ...
    "workDir","C:\Work\myfiles")

    Input Arguments

    collapse all

    Name of example to open, specified as a string scalar or character vector.

    Example: openExample("graphics/Create2DLinePlotsExample")

    Example: openExample("matlab/PlotCurveAppExample")

    Name of supporting file to open, specified as a string scalar or character vector. openExample opens the specified supporting file in the appropriate application.

    sfile can be any supporting file included in a MathWorks® example (since R2023b). Specifying a folder, project file, the main example file, or a supporting file in a subfolder is not supported. If sfile does not include an extension, openExample looks for files with a .m, .mlx, or .slx extension.

    The product that includes the example and supporting file must be installed.

    Example: openExample("parabola.m")

    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: openExample("graphics/Create2DLinePlotsExample",workDir="C:\Work\myfiles")

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: openExample("graphics/Create2DLinePlotsExample","workDir","C:\Work\myfiles")

    Folder to download example into, specified as a string scalar or character vector.

    Example: openExample("graphics/Create2DLinePlotsExample",workDir="C:\Work\myfiles")

    Supporting file to open, specified as a string scalar or character vector. When specified, openExample opens the supporting file instead of the example file in the appropriate application.

    supportingFile can be any supporting file included in a MathWorks example. Specifying a folder, project file, the main example file, or a supporting file in a subfolder is not supported. If supportingFile does not include an extension, openExample looks for files with a .m, .mlx, or .slx extension.

    The product that includes the example and supporting file must be installed.

    Example: openExample("matlab/AnalyzeTextDataExample",supportingFile="sonnets.txt")

    Version History

    Introduced in R2016a

    expand all