How to read popup menu string and use it in another button function? MATLAB GUI

I have a problem with reading a popup menu string and using it in a switch-case function in another button. My popup menu shouldn't have any function but indicating the value. But the button should know the value of popup menu and switch the case according to it. Thanks in advance.
My code:
function pushbutton1_Callback(hObject, eventdata, handles)
switch popupmenu4value
case 'A'
%function of A
case 'B'
%function of B
function popupmenu4_Callback(hObject, eventdata, handles)
contents = get(handles.popupmenu4,'String');
popupmenu4value = contents{get(handles.popupmenu4,'Value')};

 Réponse acceptée

contents = get(handles.popupmenu4,'String');
popupmenu4value = contents{get(handles.popupmenu4,'Value')};

4 commentaires

Ekin
Ekin le 23 Août 2013
Modifié(e) : Ekin le 23 Août 2013
Thanks for answer.
But it gives me "Undefined function or variable 'popupmenu4value'." on "switch" line of the button when i press the button.
function pushbutton1_Callback(hObject, eventdata, handles)
contents = get(handles.popupmenu4,'String');
popupmenu4value = contents{get(handles.popupmenu4,'Value')};
switch popupmenu4value
case 'A'
%function of A
case 'B'
%function of B
end
and clear out your function popupmenu4_Callback as it will not be needed.
Thanks solved!
Mark as "Accepted" then, so people like me don't have to waste time and come in and read all the way to the bottom only to discover it's been solved already.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Entering Commands dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by