GUI guide edit box

3 次查看(过去 30 天)
Jovos
Jovos 2016-3-23
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.

回答(1 个)

Walter Roberson
Walter Roberson 2016-3-23
  2 个评论
Jovos
Jovos 2016-3-23
Can you be more specific?
Walter Roberson
Walter Roberson 2016-3-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by