how to change static text in MATLAB GUI?

 採用された回答

Image Analyst
Image Analyst 2015 年 7 月 7 日

2 投票

First make up your string. Then set the 'String' property of the static text control to that string with the set() command. If it's in an intensive loop, you might have to use drawnow to get it to update immediately.
myString = sprintf('Hello world!\nThe value is %d', someVariable);
set(handles.text1, 'String', myString);
drawnow; % Needed only if this is in a fast loop.

7 件のコメント

Bachtiar Muhammad Lubis
Bachtiar Muhammad Lubis 2019 年 2 月 9 日
@image analyst: your code is more simple. thanks sir !
Image Analyst
Image Analyst 2019 年 2 月 9 日
It's even simpler if you use OOP syntax:
handles.text1.String = myString; % Do it like this instead of using set()
Poorna Hewapathirana
Poorna Hewapathirana 2019 年 3 月 19 日
Thans a lot. Thats very helpful
Sadat Azad
Sadat Azad 2020 年 2 月 7 日
@Image Analyst
Is there a way to permanently edit the static text, so that when launch the GUI again some other time, the text will be the updated one?
Image Analyst
Image Analyst 2020 年 2 月 7 日
You can save the new value in a .mat file,
save('app settings.mat', 'myString');
then when your startup code runs again, load() the mat file and assign the prior/saved string to the control.
myString = load('app settings.mat', 'myString'); % Get string from mat file.
handles.text1.String = myString; % Send string to static text control on GUI.
Sadat Azad
Sadat Azad 2020 年 2 月 8 日
Thanks, I was planning to save the string in a text file, This seems like a better idea.
Rik
Rik 2020 年 2 月 8 日
If you want to bind the defaults to your copy of Matlab instead of the current folder, you can use setpref and getpref.

サインインしてコメントする。

その他の回答 (1 件)

Sid
Sid 2015 年 7 月 7 日

0 投票

A very basic example:
f = figure;
t = uicontrol(f,'Style','text',...
'String','Select a data set.',...
'Position',[30 50 130 30]);
t.String = 'hello World';
This changes the static text from 'Select a data set.' to 'hello World'
Basically, all you are doing is changing the string property in an object that is of style text .
Does that help?

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

質問済み:

2015 年 7 月 7 日

コメント済み:

Rik
2020 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by