Display Custom Examples

How to Display Examples

If you have videos, published program scripts, or other files that illustrate the use of your programs, you can display these examples in a MATLAB® browser, as follows.

  1. Create your example files. Store the files in a folder that is on the MATLAB search path, but outside the matlabroot folder.

      Tip   MATLAB includes a publishing feature that converts scripts or functions to formatted HTML files, which you can display as examples. For information about creating these HTML files, see Publishing MATLAB Code.

  2. Create a demos.xml file that describes the name, type, and display information for your examples.

    For example, suppose you have a toolbox named My Sample, which contains a script named my_example that you published to HTML. This demos.xml file allows you to display my_example and a MATLAB video:

    <?xml version="1.0" encoding="utf-8"?>
    <demos>
        <name>My Sample</name>
        <type>toolbox</type>
        <icon>HelpIcon.DEMOS</icon>
        <description>This text appears on the main page for your examples.</description>
        <website><a href="http://www.mathworks.com">Link to your Web site</a></website>
    
        <demosection>
            <label>First Section</label>
            <demoitem>
                <label>My Example Title</label>
                <type>M-file</type>
                <source>my_example</source>
            </demoitem>
        </demosection>
    
        <demosection>
            <label>Second Section</label>
            <demoitem>
                <label>My Video (5 min, 21 sec)</label>
                <type>video</type>
                <callback>
                  playbackdemo('WorkingInTheDevelopmentEnvironment','toolbox/matlab/web/demos');
                </callback>
            </demoitem>
        </demosection>
    
    </demos>

      Note:   <demosection> elements are optional.

  3. View your examples.

    1. In the Help browser, navigate to the home page.

    2. At the bottom of the home page, click Supplemental Software.

      The Supplemental Software browser opens in a new window. The Contents pane contains an Examples node, which contains the entries corresponding to your demos.xml file.

        Tip   If your examples do not appear, refresh the browser. In the Contents pane, right-click Examples, and then select Refresh Examples.

        Alternatively, force a refresh by removing the folder that contains demos.xml from the path, and then adding it back. When you add the folder back to the path, make sure it is not the current folder.

Elements of the demos.xml File

General Information in <demos>

Within the demos.xml file, the root tag is <demos>. This tag includes elements that determine the contents of the main page for your examples.

XML Tag

Notes 

<name>

Name of your toolbox or collection of examples.

<type>

Possible values are matlab, simulink, toolbox, or blockset.

<icon>

Icon for your example. You can use a standard icon, HelpIcon.DEMOS, or provide a custom icon by specifying a path to the icon relative to the location of the demos.xml file.

<description>

The description that appears on the main page for your examples.

<website>

(Optional) Link to a Web site. For example, MathWorks® examples include a link to the product page at http://www.mathworks.com.

Categories Using <demosection> (Optional)

Define categories for your examples by including a <demosection> for each category. If you include any categories, then all examples must be in categories.

Each <demosection> element contains a <label> that provides the category name, and the associated <demoitem> elements.

Information About Each Example in <demoitem>

XML Tag

Notes 

<label>

Defines the title to display in the browser.

<type>

Possible values are M-file, model, M-GUI, video, or other.

<source>

If <type> is M-file, model, M-GUI, then <source> is the name of the associated .m file or model file, with no extension. Otherwise, do not include a <source> element, but include a <callback> element.

<file>

Use this element only for examples with a <type> value other than M-file when you want to display an HTML file that describes the example. Specify a relative path from the location of demos.xml.

<callback>

Use this element only for examples with a <type> value of video or other to specify an executable file or a MATLAB command to run the example.

<dependency>

(Optional) Specifies other products required to run the example, such as another toolbox. The text must match a product name specified in an info.xml file that is on the search path or in the current folder.

Thumbnail Images

If your example has an HTML file to describe it, you can include a thumbnail, a small image typifying the example. The demos.xml file does not specify thumbnail images directly.

To include a thumbnail, supply a .png image file in the same folder as the HTML file. Keep the image size to within 96-by-64 pixels (width-by-height). Give the .png file the same name as the HTML file. Thus, if the <file> element for your example is ./html/my_example.html, then your thumbnail must be named my_example.png and reside in the same folder.

When you publish a script to HTML within MATLAB, you get a .png thumbnail file in the correct place with the correct name by default.

Was this topic helpful?