How to Create a Hyperlink Component in MATLAB?
Last Updated :
23 Feb, 2022
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.
Example1:
Matlab
% MATLAB code for hlink()
fig = uifigure;
hlink = uihyperlink(fig);
hlink.Text = 'geeksforgeeks';
hlink.URL = 'https://www.geeksforgeeks.org/';
Output:

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 :
Matlab
% MATLAB code for tooltip
hlink.URL = 'https://www.geeksforgeeks.org';
hlink.Tooltip = hlink.URL;
Output:

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.
Example 3:
Matlab
% MATLAB code for Open File on Click using hlink
program = fullfile(matlabroot,'help','techdoc', ...
'matlab_env','examples','fourier_demo2.m');
copyfile(program);
htmlFile = publish('fourier_demo2.m');
fig = uifigure;
hlink = uihyperlink(fig);
hlink.URL = ['file:///' htmlFile];
Make a component with a hyperlink. To get MATLAB to open a file, use the file:/// URL scheme.
Output:

Take another example for sending an email on click.
Example 4:
Matlab
% MATLAB code for uihyperlink
fig = uifigure;
hlink = uihyperlink(fig);
Replace the value for an email with a valid email address to run this example.
Matlab
% MATLAB code for hlink.URL
email = '[email protected]';
hlink.URL = ['mailto:' email];

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.
Example 5:
Matlab
% MATLAB code for hlinkplot
function hyperlinkPlot
% Create a figure window and UI axes
fig = uifigure;
ax = uiaxes(fig);
% Create a hyperlink
hlink = uihyperlink(fig,...
'Position',[200 350 70 22], ...
'Text','GFG', ...
'URL','https://www.geeksforgeeks.org//', ...
'HyperlinkClickedFcn',@(hlink,event) plotHyperlinkClicked(hlink,ax));
end
% Create the function for the HyperlinkClickedFcn callback
function plotHyperlinkClicked(hlink, ax)
L = 160*membrane(1,100);
s = surf(ax,L);
s.EdgeColor = 'none';
end
Output:
Similar Reads
How to Create an Image Component in MATLAB?
MATLAB is an extensive tool that provides various options to its users. Creating image components is one of those tools. MATLAB provides simple functions to create image components. The uiimage function creates a new image component in a new figure by calling on the uifigure function. Usage of uiima
2 min read
How to create a textarea component in MATLAB
Matlab offers tools for developing GUI applications. It provides functions that can create TextFields, Labels, Buttons, and many more, along with properties to manipulate the components. In this article, we will learn to create a TextArea Component using Matlab. Creating a textarea componentA Text A
4 min read
How To Add an EditField Component in MATLAB?
An EditField component in MATLAB is a user interface control that allows you to input and edit text. It is a useful tool for creating user-friendly GUI (Graphical User Interface) applications. In this article, we will explain how to add an EditField component to a GUI and show some examples of its u
4 min read
How to Create a Hyperlink in HTML?
If we want to navigate from one page to another then Hyperlink comes into play. It provides you the link to navigate to another page, on hovering that link the cursor turns into a little hand. Hyperlink enables us to connect one page to another, navigate to specific sections, or even open applicatio
2 min read
Create a Slider Component in MATLAB
A slider component is a graphical interface that allows the end users to select discrete values in the range of the slider component. MATLAB provides built-in functionalities to create slider components in a MATLAB figure component. This article will explain how to create a slider component in MATLA
3 min read
DatePicker Component in MATLAB
MATLAB app builder helps in building apps in GUI without having proper software development knowledge. Matlab helps you create professional apps hassle-free, using it. There are so many components available in Matlab App Builder. You can find them all under the Component Library dialog box. This is
6 min read
How to Create Mail and Phone Link in HTML?
The HTML provides mailto and tel attributes to create the mail and phone links. We can use them in href to create the links. The href provides other sub-attributes that define the other properties of the mailto and phone link. Creating a Mailto LinkA mailto link is an easy way for users to contact w
2 min read
How to Add a Hyperlink in MS Word
Adding clickable links to your document is a simple yet powerful way to connect readers to external websites, email addresses, or even other sections within the same file. Knowing how to add a hyperlink in MS Word allows you to enhance your content and improve navigation for your audience. Whether y
3 min read
How to create a function in MATLAB ?
A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: fun
2 min read
How to Append Data to a File in MATLAB?
Appending data to a text file means adding data to a file that already exists in the storage. print() function is used to write/append data to a file in MATLAB. It writes formatted text to a file based on the format string provided to it. The format of the output/input is determined by the formattin
4 min read