MATLAB Community

MATLAB, community & more

Printing hyperlinks to the Command Window

I quite often get asked how to print out hyperlinks to the Command Window. It’s really easy! The Command Window accepts <a href tags that contain valid links. Valid links contain http:// or matlab:. The Command Window treats any text after the matlab: syntax, inside the quote marks, as executable M-code.

Here are some examples of hyperlinks in the Command Window.

Hyperlink to a web page

disp('This is a link to <a href="http://www.google.com">Google</a>.')

Hyperlink to M-code

disp('You should <a href="matlab: plot(magic(10)), disp(''I plotted some stuff'')">my code</a>!')

I used the disp command, but you could also use the fprintf command to achieve the same effect.

To open an m-file from the Command Window, disp a matlab: link that uses the function opentoline:

disp('You should <a href="matlab: opentoline(which(''why.m''),27)">open my file</a>!')

These lines of code can be placed in any M-file or in any shortcut on the Desktop toolbar.

The Command Window is not an HTML renderer, so it won’t interpret other types of html tags – just the <a href tag.

|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。