Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to display default values in GUI?

Subject: How to display default values in GUI?

From: Chris Sorrento

Date: 19 Jul, 2010 14:19:05

Message: 1 of 4

I have designed a GUI with multiple textboxes where I collect user input values (numerical values) and pass them to a function file for evaluation. But there are too many textboxes. To make the GUI more user friendly, I put default/suggested values in the "String" property of PropertyInspector. But Matlab reads that as []. So, I have to put my curser in each box and then either hit enter or tab to next textbox. This defeats the purpose of putting in default values. Any suggestions as to how I can get around this? I guess same question applies to other components in GUI - list, slider, radio buttons. Thank you in advance for taking time to read this.

Subject: How to display default values in GUI?

From: Sean

Date: 19 Jul, 2010 15:35:04

Message: 2 of 4

"Chris Sorrento" <remove.this.string.agairan@hotmail.com> wrote in message <i21msp$db5$1@fred.mathworks.com>...
> I have designed a GUI with multiple textboxes where I collect user input values (numerical values) and pass them to a function file for evaluation. But there are too many textboxes. To make the GUI more user friendly, I put default/suggested values in the "String" property of PropertyInspector. But Matlab reads that as []. So, I have to put my curser in each box and then either hit enter or tab to next textbox. This defeats the purpose of putting in default values. Any suggestions as to how I can get around this? I guess same question applies to other components in GUI - list, slider, radio buttons. Thank you in advance for taking time to read this.


%Did you create your GUI with GUIDE?
%
%In your code opening function:
set(handles.your_textbox,'String','Default Value');
%
%To retrieve the values for your functions
numeric_value = str2num(get(handles.your_textbox,'String'));


You can use setappdata/getappdata with your handles to make the value retrievable from functions that will always need them too.
%E.g. in your opening function:
setappdata(0,'Hyour_textbox',handles.your_textbox);

%in function fun(in)
function out = fun(x)
H = getappdata(0,'Hyour_textbox');
Val = str2num(get(H,'String'));
out = Val^2*pi/in;

Subject: How to display default values in GUI?

From: Chris Sorrento

Date: 19 Jul, 2010 16:07:04

Message: 3 of 4

Thank you Sean. I did create the GUI using GUIDE and I was simply changing the "String" value from within PropertyInspector. But as you have suggested, I might need to add this code that you suggested into the GUI .m file. That is exactly the guidence I was looking for. Thanks for your help.

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i21rb8$2iu$1@fred.mathworks.com>...
> > I have designed a GUI with multiple textboxes where I collect user input values (numerical values) and pass them to a function file for evaluation. But there are too many textboxes. To make the GUI more user friendly, I put default/suggested values in the "String" property of PropertyInspector. But Matlab reads that as []. So, I have to put my curser in each box and then either hit enter or tab to next textbox. This defeats the purpose of putting in default values. Any suggestions as to how I can get around this? I guess same question applies to other components in GUI - list, slider, radio buttons. Thank you in advance for taking time to read this.
>
>
> %Did you create your GUI with GUIDE?
> %
> %In your code opening function:
> set(handles.your_textbox,'String','Default Value');
> %
> %To retrieve the values for your functions
> numeric_value = str2num(get(handles.your_textbox,'String'));
>
>
> You can use setappdata/getappdata with your handles to make the value retrievable from functions that will always need them too.
> %E.g. in your opening function:
> setappdata(0,'Hyour_textbox',handles.your_textbox);
>
> %in function fun(in)
> function out = fun(x)
> H = getappdata(0,'Hyour_textbox');
> Val = str2num(get(H,'String'));
> out = Val^2*pi/in;

Subject: How to display default values in GUI?

From: Andy

Date: 19 Jul, 2010 16:53:03

Message: 4 of 4

"Chris Sorrento" <remove.this.string.agairan@hotmail.com> wrote in message <i21msp$db5$1@fred.mathworks.com>...
> I have designed a GUI with multiple textboxes where I collect user input values (numerical values) and pass them to a function file for evaluation. But there are too many textboxes. To make the GUI more user friendly, I put default/suggested values in the "String" property of PropertyInspector. But Matlab reads that as []. So, I have to put my curser in each box and then either hit enter or tab to next textbox. This defeats the purpose of putting in default values. Any suggestions as to how I can get around this? I guess same question applies to other components in GUI - list, slider, radio buttons. Thank you in advance for taking time to read this.

Can you describe your problem in more detail? What do you mean by "too many textboxes"? Are your textboxes what GUIDE calls Edit Text boxes? What are some of your values which are not being correctly read? And what do you mean by "MATLAB reads that as []"? Are you saving your .fig file before re-running your GUI?

When I create a new file in GUIDE, add an Edit Box, change the String field, save, and then run the GUI, I see a GUI with an editable text box that, by default, contains whatever I entered as the String. I cannot reproduce the error you've described.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us