MATLAB Answers

how to change static text in MATLAB GUI?

502 views (last 30 days)
Kobi
Kobi on 7 Jul 2015
Commented: Rik on 8 Feb 2020
how to change static text in MATLAB GUI?

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Jul 2015
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 Comments

Show 4 older comments
Image Analyst
Image Analyst on 7 Feb 2020
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 on 8 Feb 2020
Thanks, I was planning to save the string in a text file, This seems like a better idea.
Rik
Rik on 8 Feb 2020
If you want to bind the defaults to your copy of Matlab instead of the current folder, you can use setpref and getpref.

Sign in to comment.

More Answers (1)

Sid
Sid on 7 Jul 2015
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?

  0 Comments

Sign in to comment.