how can add an text on GUI

조회 수: 74 (최근 30일)
yasmeen hadadd
yasmeen hadadd 2024년 7월 23일
답변: Voss 2024년 7월 23일
hi
how i can diplay or show data on text area in GUI matalb
  댓글 수: 1
Umar
Umar 2024년 7월 23일

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.

댓글을 달려면 로그인하십시오.

답변 (2개)

Muskan
Muskan 2024년 7월 23일
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 2024년 7월 23일

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by