Main Content

openExample

Open a MathWorks example

    Description

    example

    openExample(examplename) copies 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.

    example

    openExample(sfile) copies 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 copy. The specified supporting file must be an executable file with a .m, .mlx, or .slx extension.

    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 copy 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 copy.

    openExample("parabola.m")

    Copy 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. sfile must be an executable file with a .m, .mlx, or .slx extension.

    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 copy 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. supportingFile can be any supporting file included in a MathWorks® 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.

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

    Version History

    Introduced in R2016a