Display Custom Examples - MATLAB & Simulink (original) (raw)

Main Content

How to Display Examples

To display examples such as videos, published program scripts, or other files that illustrate the use of your programs within the MathWorks® documentation, follow these steps:

  1. Create your example files. To create examples from scripts or functions, you can convert the files to formatted HTML files in MATLAB® using either of these two methods:
    • Create a live script (*.mlx) and export it to HTML. For more information, see Ways to Share and Export Live Scripts and Functions.
    • Create a script (*.m), and publish it to HTML. For more information, see Publish and Share MATLAB Code.
      Store all your example files and any supporting files (such as PNG and CSS files) for your toolbox in the folder (of a subfolder of the folder) that contains your demos.xml file. This folder must be:
    • On the MATLAB search path
    • Outside the_`matlabroot`_ folder
    • Outside any installed hardware support package help folder
  2. Create a demos.xml file that describes the name, type, and display information for your examples. Place the file in the folder (or a subfolder of the folder) that contains your info.xml file. For more information about creating an info.xml file, see Display Custom Documentation.
    For example, suppose that you have a toolbox named My Sample, which contains a script namedmy_example that you published to HTML. Thisdemos.xml file allows you to displaymy_example: My Sample toolbox HelpIcon.DEMOS This text appears on the main page for your examples. Link to your Web site First Section My Example Title M-file my_example
  3. View your examples.
    In your system web browser, navigate to the MathWorks documentation home page. On the left side of the home page, under Supplemental Software, click the link for your example.
    If your examples do not display under Supplemental Software, the demos.xml file might contain an invalid construct.

Elements of the demos.xml File

Within the demos.xml file, you can include general information in the <demos> tag, define individual examples using the<demoitem> tag, and optionally define categories using the<demosection> tag.

Include General Information Using <demos> Tag

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 of your toolbox or collection of examples.
Possible values are matlab,simulink, toolbox, or blockset.
Ignored in MATLAB R2015a and later.In previous releases, this icon was the icon for your example. In those releases, you can use a standard icon,HelpIcon.DEMOS. Or, you can provide a custom icon by specifying a path to the icon relative to the location of the demos.xml file.
The description that appears on the main page for your examples.Starting in R2021a, character data is not supported in the description of thedemos.xml file. If yourdemos.xml file contains character data such as <,>,',", and& in the description, the description does not appear correctly in the documentation. To automatically replace existing character data with non-character data, use the patchdemoxmlfile function.
(Optional) Link to a website. For example, MathWorks examples include a link to the product page athttps://www.mathworks.com.

Define Examples Using <demoitem> Tag

XML Tag Notes
Defines the title to display in the browser.
Possible values are M-file,model, M-GUI,video, or other.Typically, if you published your example using the publish function, the appropriate isM-file.
If isM-file, model,M-GUI, then is the name of the associated .m file or model file, with no extension. Otherwise, do not include a element, but include a element.
Use this element only for examples with a value other thanM-file when you want to display an HTML file that describes the example. Specify a relative path from the location of demos.xml.
Use this element only for examples with a value ofvideo or other to specify an executable file or a MATLAB command to run the example.
(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.

Define Categories Using <demosection> Tag

Optionally, 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.

See Also

patchdemoxmlfile

Topics