how can add an text on GUI

73 views (last 30 days)
yasmeen hadadd
yasmeen hadadd on 23 Jul 2024
Answered: Voss on 23 Jul 2024
hi
how i can diplay or show data on text area in GUI matalb
  1 Comment
Umar
Umar on 23 Jul 2024

Hi yasmeen,

Try using the uicontrol function to create a text area (uicontrol of style 'text'). Then, you can set the 'String' property of the text area to the data you want to display. Here is a simple example:

% Create a GUI figure

fig = figure;

% Create a text area

txt = uicontrol('Style', 'text', 'Position', [50, 50, 200, 100], 'String', 'Your Data Here');

% Update the text area with new data

new_data = 'New Data to Display';

set(txt, 'String', new_data);

So, in the above code snippet, I first created a GUI figure, then a text area with initial data. Later, I updated the text area with new data by setting the 'String' property of the text area. This approach will allow you to dynamically display data on a text area within your MATLAB GUI.

Note: When I executed the code using mobile Matlab, a warning message was displayed like the one shown below. However, the main point was to answer your question which was displaying data on a text area. Warning: In a future release, UI components will not be included in the output. To include UI components, use the exportapp function.

Please see attached result.

I hope this answers your question.

Sign in to comment.

Answers (2)

Muskan
Muskan on 23 Jul 2024
In MATLAB, you can display data in a text area within a graphical user interface (GUI) using the "uicontrol" function.
Here is a sample code snippet on how you can do that:
function simple_gui_with_text_area
% Create a figure for the GUI
fig = figure('Position', [100, 100, 400, 300], 'Name', 'Simple GUI with Text Area', 'NumberTitle', 'off');
% Create a text area
txtArea = uicontrol('Style', 'edit', ...
'Max', 2, 'Min', 0, ... % Allows for multiline text
'Position', [50, 50, 300, 200], ...
'HorizontalAlignment', 'left', ...
'FontSize', 10, ...
'BackgroundColor', 'white');
% Data to display in the text area
data = {'This is line 1', ...
'This is line 2', ...
'This is line 3', ...
'This is line 4'};
% Convert cell array of strings to a single string with new lines
dataStr = strjoin(data, '\n');
% Display data in the text area
set(txtArea, 'String', dataStr);
end
Here, ou can modify the "data" variable to display any text you want in the text area.
Additonally, you can also use the function "uitextarea" to create a text area component. Please refer to the documentation of "uitextarea" for more information: https://www.mathworks.com/help/matlab/ref/uitextarea.html

Voss
Voss on 23 Jul 2024

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!