| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
disp('<a href="matlab: stmnt_1; stmnt_n;">hyperlink_text</a>')
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—you might need to use HTML character entity references or ASCII values for some 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. No spaces are allowed after the opening < and before the closing >. A single space is required between a and href.
The matlab: function behaves differently with diary, notebook, type, and similar functions than might be expected. For example, if you enter the following statement
disp('<a href="matlab:magic(4)">Generate magic square</a>')
the diary file, when viewed in a text editor, shows
disp('<a href="matlab:magic(4)">Generate magic square</a>')
<a href="matlab:magic(4)">Generate magic square</a>
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.
The statement
disp('<a href="matlab:magic(4)">Generate magic square</a>')
displays
![]()
in the Command Window. When you click the link Generate magic square, the MATLAB software runs magic(4).
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
x = 0:1:8; y = sin(x); plot(x,y)
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
x = -2*pi:pi/16:2*pi;
If you then click the hyperlink, Plot x,y, it changes the current value of x back to
0:1:8
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.
Use multiple matlab: statements in an M-file to present options, such as
disp('<a href = "matlab:state = 0">Disable feature</a>')
disp('<a href = "matlab:state = 1">Enable feature</a>')
The Command Window displays
![]()
and depending on which link is clicked, sets state to 0 or 1.
MATLAB correctly interprets most strings that includes special characters, such as a greater than sign (>). For example, the following statement includes a >
disp('<a href="matlab:str = ''Value > 0''">Positive</a>')and generates the following hyperlink.
![]()
Some symbols might not be interpreted correctly and you might need to use the HTML character entity reference for the symbol. For example, an alternative way to run the same statement is to use the > character entity reference instead of the > symbol:
disp('<a href="matlab:str = ''Value > 0''">Positive</a>')
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
disp('<a href="matlab:str=[''Value '' char(62) '' 0'']">Positive</a>')Here are some values for common special characters.
Character | HTML Character Entity Reference | ASCII Value |
|---|---|---|
62 | ||
60 | ||
38 | ||
34 |
For a list of all HTML character entity references, see http://www.w3.org/.
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:
function c=soundspeed(s,t,p)
% Speed of sound in water, using
% <a href="matlab: web('http://www.zu.edu')">Wilson's formula</a>
% Where c is the speed of sound in water in m/s
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 intentionally invalid.
disp, error, fprintf, input, run, warning
![]() | material | matlabrc | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |