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
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Software Development Life Cycle (SDLC) Software development life cycle (SDLC) is a structured process that is used to design, develop, and test good-quality software. SDLC, or software development life cycle, is a methodology that defines the entire procedure of software development step-by-step. The goal of the SDLC life cycle model is
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Waterfall Model - Software Engineering The Waterfall Model is a Traditional Software Development Methodology. It was first introduced by Winston W. Royce in 1970. It is a linear and sequential approach to software development that consists of several phases. This classical waterfall model is simple and idealistic. It is important because
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read