Azzera filtri
Azzera filtri

I need help with GUI

3 visualizzazioni (ultimi 30 giorni)
Madeleine
Madeleine il 6 Mag 2014
Risposto: Sara il 6 Mag 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 Commento
nl2605
nl2605 il 6 Mag 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.

Accedi per commentare.

Risposta accettata

Sara
Sara il 6 Mag 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);

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by