フィルターのクリア

I need help with GUI

3 ビュー (過去 30 日間)
Madeleine
Madeleine 2014 年 5 月 6 日
回答済み: Sara 2014 年 5 月 6 日
So far I have a pushbutton and a textbox printed into a new window (figure).
When I click the pushbutton, I want the push button to increment by one.
Then whatever value is on the pushbutton at that time I want it displayed in the text box.
The question is, how do I do it.
I need to add something to my code below, but that something is bot striking my mind at the moment.
Please help someone* .* *
function function_name()
fig = figure();
buttonA = uicontrol('position',[300 400 60 60],'style', 'pushbutton','Callback',@display_A_value);
textA = uicontrol('position',[500 400 60 60],'style', 'text');
set(buttonA, 'callback', {@display_A_value,1});
function display_A_value(hObject,eventdata)
set(textA, 'string', num2str(WHAT DO I PUT HERE));
end
end
  1 件のコメント
nl2605
nl2605 2014 年 5 月 6 日
You can assign a variable var = 1; in the workspace. And pass var to your callback function. Keep incrementing it var = var + 1; And put it in num2str. I am not sure it will work. You can try. I am also not sure if its the best method.

サインインしてコメントする。

採用された回答

Sara
Sara 2014 年 5 月 6 日
Define a variable that counts how many time the pushbutton has been pressed and set it to zero in the OpeningFcn as:
handles.mycounter = 0;
Make sure you have the command:
guidata(hObject, handles);
at the end of such function. Now, in the body of the pushbutton callback, do:
handles.mycounter = handles.mycounter + 1;
set(textA, 'string', handles.mycounter);
guidata(hObject, handles);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by