I need help with GUI
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
nl2605
am 6 Mai 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.
Akzeptierte Antwort
Sara
am 6 Mai 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);
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!