GUI guide edit box

1 回表示 (過去 30 日間)
Jovos
Jovos 2016 年 3 月 23 日
コメント済み: Walter Roberson 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by