How to reset the pop-up menu value in GUI?
Mostra commenti meno recenti
Hi,
This is my pop-up coding.
function Domain_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'string'));
popchoice = contents{get(hObject,'value')};
if (strcmp(popchoice, 'Time Domain'))
Domain_value = 2;
elseif (strcmp(popchoice, 'Frequency Domain'))
Domain_value = 3;
elseif (strcmp(popchoice, '----'))
Domain_value = 1;
end
assignin('base', 'Domain_value', Domain_value);
And this is my reset button function
function Clear_button_Callback(hObject, eventdata, handles)
set(handles.Domain,'Value',1);
It partly works. In GUI if I press the reset button, the pop-up menu will show '----', but the value won't change.
So how can I reset the pop-up value to 1?
6 Commenti
Geoff Hayes
il 11 Mar 2020
Jomei - which value won't change? Do you mean the Domain_value in the base workspace? I doubt the Domain_Callback is being called when you do
set(handles.Domain,'Value',1);
Jomei
il 11 Mar 2020
Geoff Hayes
il 11 Mar 2020
Right, because calling
set(handles.Domain,'Value',1);
does not call the Domain_Callback where you set the Domain_value. Do you need this value in the base workspace? How is it used?
Jomei
il 11 Mar 2020
Geoff Hayes
il 11 Mar 2020
Jomei - but you do understand why the value is not being set in the workspace, correct? And do you really need it to be defined in the workspace? If so, why?
Jomei
il 13 Mar 2020
Risposte (2)
Rik
il 11 Mar 2020
0 voti
If you need something in your base workspace to be updated when you change things in your GUI, you could consider a programmatic class-based GUI. The example in the how to create a GUI thread should be relatively easy to adapt to your needs.
This different design would also remove the need for assignin.
1 Commento
Jomei
il 13 Mar 2020
1 Commento
Rik
il 13 Mar 2020
You should really avoid that strategy. It is very prone to breaking in ways that are difficult to diagnose. You should really consider changing your setup to one of the ways described in the link I posted.
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!