I need help with GUI

8 views (last 30 days)
Madeleine
Madeleine on 6 May 2014
Answered: Sara on 6 May 2014
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 Comment
nl2605
nl2605 on 6 May 2014
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.

Sign in to comment.

Accepted Answer

Sara
Sara on 6 May 2014
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);

More Answers (0)

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!