Effacer les filtres
Effacer les filtres

I need help with GUI

3 vues (au cours des 30 derniers jours)
Madeleine
Madeleine le 6 Mai 2014
Réponse apportée : Sara le 6 Mai 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 commentaire
nl2605
nl2605 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Sara
Sara le 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);

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by