{"id":7732,"date":"2017-03-17T14:11:36","date_gmt":"2017-03-17T18:11:36","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=7732"},"modified":"2017-03-17T14:11:36","modified_gmt":"2017-03-17T18:11:36","slug":"hyperlink","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2017\/03\/17\/hyperlink\/","title":{"rendered":"Hyperlink"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/58-routh-m\">Hyperlink<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8426716\">Michele Scalseggi<\/a>.\r\n\r\n&nbsp;\r\n\r\nHave you ever wanted to quickly put a hyperlink at the command line or in the help for a function you're writing? What about\r\na link that when clicked <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/create-hyperlinks-that-run-functions.html\">evaluates some MATLAB code<\/a>?\r\n\r\nMichele's easy to use Hyperlink command will do this for you. It interprets whether you're targeting a website or MATLAB\r\nexpression and builds the link so that when displayed at the command line will do what you want.\r\n\r\nFor example, let's put <i>\"why\"<\/i> at the command line so that when you click the link it evaluates <tt>why()<\/tt>:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHyperlink\/why1.png\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nAlternatively, let's have it take you to MathWorks' website:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHyperlink\/mathworkswebsite.png\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nWe could easily pass this into <tt>fprintf<\/tt> or <tt>disp<\/tt> to make a nice sentence with hyperlinks. Here's a <i>Matrix<\/i> themed example:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHyperlink\/rbpill.gif\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nFinally, perhaps you want to put a hyperlink in the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-help-for-your-program.html\"><tt>help<\/tt><\/a> of a function you're writing. I'd encourage you to use the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/clipboard.html\"><tt>clipboard<\/tt><\/a> command to directly copy it in.\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">clipboard(<span style=\"color: #a020f0;\">'copy'<\/span>,Hyperlink(<span style=\"color: #a020f0;\">'edit(''example.m'')'<\/span>,<span style=\"color: #a020f0;\">'Open Example'<\/span>))<\/pre>\r\nSo now you can paste this into the help of your function directly\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\"><span style=\"color: #0000ff;\">function<\/span> y = myfun(x)\r\n<span style=\"color: #228b22;\">% MYFUN takes the sin of x<\/span>\r\n<span style=\"color: #228b22;\">%<\/span>\r\n<span style=\"color: #228b22;\">% &lt;a href=\"matlab:edit('example.m')\"&gt;Open Example&lt;\/a&gt;<\/span>\r\n<span style=\"color: #228b22;\">% <\/span>\r\n\r\ny = sin(x);\r\n<\/pre>\r\nThen asking for help on myfun will show the link:\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHyperlink\/customhelp.png\" hspace=\"5\" vspace=\"5\" \/>\r\n<h3>Comments<a name=\"2\"><\/a><\/h3>\r\nGive it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=7732#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/58-routh-m#comments\">comment<\/a> for Michele.\r\n\r\n<script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_87f8b17a78d740779b9cef4d1b285e2e() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='87f8b17a78d740779b9cef4d1b285e2e ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 87f8b17a78d740779b9cef4d1b285e2e';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Sean de Wolski';\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<\/p>\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n<p>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2016b<\/p>\r\n\r\n<\/div>\r\n<!--\r\n87f8b17a78d740779b9cef4d1b285e2e ##### SOURCE BEGIN #####\r\n%% Hyperlink\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/58-routh-m Hyperlink> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/8426716 Michele Scalseggi>.\r\n%\r\n\r\n%%\r\n% Have you ever wanted to quickly put a hyperlink at the command line or in\r\n% the help for a function you're writing?  What about a link that when\r\n% clicked\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/create-hyperlinks-that-run-functions.html % evaluates some MATLAB code>?\r\n%\r\n% Michele's easy to use Hyperlink command will do this for you.  It\r\n% interprets whether you're targeting a website or MATLAB expression and\r\n% builds the link so that when displayed at the command line will do what\r\n% you want.\r\n%\r\n% For example, let's put _\"why\"_ at the command line so that when you click the link it evaluates |why()|:\r\n%\r\n% <<why1.png>>\r\n%\r\n% Alternatively, let's have it take you to MathWorks' website:\r\n%\r\n% <<mathworkswebsite.png>>\r\n%\r\n% We could easily pass this into |fprintf| or |disp| to make a nice sentence with\r\n% hyperlinks.  Here's a _Matrix_ themed example:\r\n%\r\n% <<rbpill.gif>>\r\n%\r\n% Finally, perhaps you want to put a hyperlink in the\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/matlab_prog\/add-help-for-your-program.html % |help|> of a function you're writing.  I'd encourage you to use the\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/clipboard.html % |clipboard|> command to directly copy it in.\r\n%\r\n%   clipboard('copy',Hyperlink('edit(''example.m'')','Open Example'))\r\n%\r\n% So now you can paste this into the help of your function directly\r\n%\r\n% <include>myfun.m<\/include>\r\n%\r\n% Then asking for help on myfun will show the link:\r\n%\r\n% <<customhelp.png>>\r\n\r\n%% Comments\r\n%\r\n% Give it a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=7732#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/58-routh-m#comments % comment> for Michele.\r\n\r\n##### SOURCE END ##### 87f8b17a78d740779b9cef4d1b285e2e\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/mainHyperlink\/why1.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nSean's pick this week is Hyperlink by Michele Scalseggi.\r\n\r\n&nbsp;\r\n\r\nHave you ever wanted to quickly put a hyperlink at the command line or in the help for a function you're writing? What... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2017\/03\/17\/hyperlink\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7732"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=7732"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7732\/revisions"}],"predecessor-version":[{"id":8478,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7732\/revisions\/8478"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=7732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=7732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=7732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}