How To Add an EditField Component in MATLAB?
Last Updated :
28 Apr, 2025
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 use.
Steps
Step 1: To add an EditField component to a GUI, you need to have a GUI already created. If you don't have a GUI, you can create one by following the steps in the official MATLAB documentation.
Step 2: Once you are done with creating a GUI, It looks like this.
Step 3: You can add an EditField component to it by dragging the "Edit Field" icon from the "Palettes" pane on the right-hand side of the GUI editor. (We have an edit field component for text and numeric you can pick based on your requirement)
Step 4: After you have added the EditField component to your GUI, you can resize it and move it to the desired location.
Step 5: To customize the EditField component, you can use the "Properties" pane on the right-hand side of the GUI editor. From the "Properties" pane, you can change the text displayed in the edit field, the font size, the background color, and other properties.
The Code for the above generated EditField Component in Matlab is given below:
Matlab
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
EditField matlab.ui.control.EditField
EditFieldLabel matlab.ui.control.Label
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create EditFieldLabel
app.EditFieldLabel = uilabel(app.UIFigure);
app.EditFieldLabel.HorizontalAlignment = 'right';
app.EditFieldLabel.Position = [141 189 56 22];
app.EditFieldLabel.Text = 'Edit Field';
% Create EditField
app.EditField = uieditfield(app.UIFigure, 'text');
app.EditField.FontSize = 14;
app.EditField.FontWeight = 'bold';
app.EditField.Position = [212 134 323 132];
app.EditField.Value = 'Hema Hariharan Samson @gfg';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Here are some examples of how you can use an EditField component in your GUI:
- Input validation: You can use an EditField component to input a numerical value and validate the input using the "isnumeric" function. If the input is not numeric, you can display an error message using a "Static Text" component.
- Filtering a list: You can use an EditField component to filter a list of items displayed in a "Listbox" component. As the user types in the EditField, you can use the "String" property to update the list displayed in the "Listbox" based on the entered text.
- Text input: You can use an EditField component to input a string of text and use it in your code. For example, you can use it to input a file name and read the file using the "fopen" function.
Method 2:
There are other ways to input text in a GUI, such as using a "Textbox" component or an "Input Dialog" function. The "Textbox" component allows you to input multi-line text, while the "Input Dialog" function displays a modal dialog box that prompts the user to input a value. You can choose the method that best suits your needs.
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