Clear Filters
Clear Filters

GUI guide edit box

3 views (last 30 days)
Jovos
Jovos on 23 Mar 2016
Commented: Walter Roberson on 23 Mar 2016
Hi, I am making a simple GUI calculator. My question is after I set up the edit box. For example:
amount = uicontrol('Style','edit','String',' ',...
'Position',[35,30,60,15],...
'Callback',{@amount_Callback});
I can type in numbers/characters there. I wonder how can I store those numbers into a variable. So that I can used them in the callback function.
Additionally, I am a bit confused how the call back function works. Say if I need that value of amount(defined above) as a variable, do I just define a new variable such as x = something?
Any information is helpful. A simple example will be great. Thank you.

Answers (1)

Walter Roberson
Walter Roberson on 23 Mar 2016
  2 Comments
Jovos
Jovos on 23 Mar 2016
Can you be more specific?
Walter Roberson
Walter Roberson on 23 Mar 2016
Inside the callback function, get() the String property of the uicontrol. You can store it in a variable. You will likely want to make the value available outside of the workspace of the callback function. Use one of the techniques described in the above link to make the value available outside of the workspace.
Note: Most commonly, callback functions for edit controls are mostly used to validate that the string is an acceptable answer, such as making sure that it looks like a number. Usually each routine that wants to use the string retrieves the String property of the control. However, this is by no means universal, and it is entirely valid to have the edit callback interpret the value and store it in a location for other values to retrieve; doing so has some advantages.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!