フィルターのクリア

how can add an text on GUI

21 ビュー (過去 30 日間)
yasmeen hadadd
yasmeen hadadd 2024 年 7 月 23 日 17:31
回答済み: Voss 2024 年 7 月 23 日 18:08
hi
how i can diplay or show data on text area in GUI matalb
  1 件のコメント
Umar
Umar 2024 年 7 月 23 日 18:01

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 日 17:59
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 日 18:08

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by