Create Hyperlinks that Run Functions
The special keyword matlab: lets you embed commands in other functions. Most
commonly, the functions that contain it display hyperlinks, which execute the commands
when you click the hyperlink text. Functions that support matlab: syntax include disp,
error, fprintf, help, and warning.
Use matlab: syntax to create a hyperlink in the Command Window that runs one or more
functions. For example, you can use disp to display the word Hypotenuse as an
executable hyperlink as follows:
disp('<a href="matlab:a=3; b=4;c=hypot(a,b)">Hypotenuse</a>')
Clicking the hyperlink executes the three commands following matlab:, resulting in
c =
5
Executing the link creates or redefines the variables a, b, and c in the base workspace.
The argument to disp is an <a href> HTML hyperlink. Include the full hypertext text,
from '<a href= to </a>' within a single line, that is, do not continue long text on a new
line. No spaces are allowed after the opening < and before the closing >. A single space is
required between a and href.
You cannot directly execute matlab: syntax. That is, if you type
matlab:a=3; b=4;c=hypot(a,b)
you receive an error, because MATLAB interprets the colon as an array operator in an
illegal context:
??? matlab:a=3; b=4;c=hypot(a,b)
|
Error: The expression to the left of the equals sign
is not a valid target for an assignment.
You do not need to use matlab: to display a live hyperlink to the Web. For example, if
you want to link to an external Web page, you can use disp, as follows:
disp('<a href="http://en.wikipedia.org/wiki/Hypotenuse">Hypotenuse</a>')
The result in the Command Window looks the same as the previous example, but instead
opens a page at en.wikipedia.org:
25 Programming Utilities