How to Create a Hyperlink Component in MATLAB?
MATLAB is a matrix-based computational environment that has its own programming language which is very easy to use and learn. It is used for heavy mathematical concepts, understanding huge data sets with the help of the GUI Graphical User Interface of MATLAB.
In GUIs, hyperlinked text labels are frequently beneficial. These labels enable one-click access to key functionality, improve branding, and are non-intrusive action controls with a smaller visual effect than full-blown buttons. There are a few different ways to display hyperlinks in Matlab GUIs, and I’ll show you one of my favorites today.
The fundamental concept is to make a Java text label control with an HTML link on the label. When the mouse pointer hovers over the hyperlink, the control is updated, and a mouse-click callback is established to open the hyperlink target in the system browser.
When we are clicking the label control rather than the hyperlink (notice that the href is empty). The end outcome is identical. Also, by simply altering the label’s HTML string to display the correct picture, this technique might be used to easily display clickable icons/images, including animated and transparent GIFs.
- hlink = uihyperlink: It returns the Hyperlink object after creating a hyperlink component in a new figure window. The default size of the link is 70 by 22 pixels, and the default text is ‘Hyperlink’.
- hlink = uihyperlink(parent): It generates a hyperlink in the parent container supplied. A figure produced with the uifigure function or one of its child containers can be the parent.
- hlink = uihyperlink( ,Name,Value): It provides hyperlink properties. The Text and URL name-value parameters, for example, can be used to specify the hyperlink’s display text and URL. Use this option with any of the previous syntax’s input argument combinations.
Let’s see different examples to connect the link with text or components. After creating Hyperlink to text it will redirect to the provided link.
To display a URL, create a tooltip. Create a default hyperlink. To link to the MathWorks home page, change the URL. When the app user holds their pointer over the hyperlink, add a tooltip that displays the URL.
Example 2 :
Open File on Click for this use the file/ URL scheme to make a link open a file on the app user’s system when clicked. Using publish, create an HTML file from an example program file. Get the path to the program file first. Then, in order for the code to run during the publishing process, copy the program file to the current folder.
Make a component with a hyperlink. To get MATLAB to open a file, use the file:/// URL scheme.
Take another example for sending an email on click.
Replace the value for an email with a valid email address to run this example.
For code response to click creates a hyperlink with a custom effect: when the app user taps it, it creates a plot and opens a URL. Create a set of UI axes and a HyperlinkClickedFcn callback that plots these axes to accomplish this.
On your MATLAB directory, create a file called hyperlinkPlot.m that has the following code. This code generates a window with a hyperlink and a set of user interface axes. When the app user clicks the link, the browser loads the MATLAB product page first, followed by the HyperlinkClickedFcn callback plotting some data.
Please Login to comment...