MATLAB Function Reference Previous page   Next Page
matlabcolon (matlab:)

Run specified function via hyperlink

Syntax

Description

matlab: executes stmnt_1 through stmnt_n when you click (or press Ctrl+Enter) in hyperlink_text. This must be used with another function, such as disp, where disp creates and displays underlined and colored hyperlink_text in the Command Window. Use disp, error, fprintf, help, or warning functions to display the hyperlink. The hyperlink_text is interpreted as HTML, so use HTML character entity references or ASCII values for special characters. Include the full hypertext string, from '<a href= to </a>' within a single line, that is, do not continue a long string on a new line.

Remarks

The matlab: function behaves differently with diary, notebook, type, and similar functions than might be expected. For example, if you enter the following statement

the diary file, when viewed in a text editor, shows

If you view the output of diary in the Command Window, the Command Window interprets the <a href ...> statement and does display it as a hyperlink.

Examples

Single Function

The statement

displays

in the Command Window. When you click the link Generate magic square, MATLAB runs magic(4).

Multiple Functions

You can include multiple functions in the statement, such as

disp('<a href="matlab: x=0:1:8;y=sin(x);plot(x,y)">Plot x,y</a>')

which displays

in the Command Window. When you click the link, MATLAB runs

Clicking the Hyperlink Again

After running the statements in the hyperlink Plot x,y defined in the previous example, Multiple Functions, you can subsequently redefine x in the base workspace, for example, as

If you then click the hyperlink, Plot x,y, it changes the current value of x back to

because the matlab: statement defines x in the base workspace. In the matlab: statement that displayed the hyperlink, Plot x,y, x was defined as 0:1:8.

Presenting Options

Use multiple matlab: statements in an M-file to present options, such as

The Command Window displays

and depending on which link is clicked, sets state to 0 or 1.

Special Characters

To create a string that includes a special character such as a greater than sign, >, you need to use the HTML character entity reference for the symbol, &gt;. Otherwise, the symbol is interpreted as completing the <a href = " ... " element. For example, run

and the Command Window displays

Instead of the HTML character entity reference, you can use the ASCII value for the symbol. For example, the greater than sign, >, is ASCII 62. The above example becomes

Use these values for common special characters.

Character
HTML Character Entity Reference
ASCII Value
>
&gt;
62
<
&lt;
60
&
&amp;
38
"
&quot;
34

Links from M-File Help

For functions you create, you can include matlab: links within the M-file help, but you do not need to include a disp or similar statement because the help function already includes it for displaying hyperlinks. Use the links to display additional help in a browser when the user clicks them. The M-file soundspeed contains the following statements:

  1. etc.

Run help soundspeed and MATLAB displays the following in the Command Window.

When you click the link Wilson's formula, MATLAB displays the HTML page http://www.zu.edu in the Web browser. Note that this URL is only an example and is invalid.

See Also

disp, error, fprintf, input, run, warning

HTML character entity references at http://www.w3.org/.


Previous page  material matlabrc Next page

© 1994-2005 The MathWorks, Inc.