Help with pop up menu in a GUI interface
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
aurc89
le 28 Jan 2015
Réponse apportée : Geoff Hayes
le 28 Jan 2015
I have to use for the first time a popup menu in a GUI interface. I know I can switch two or more options with it; for example, if 'plot1' and 'plot2' are the two cases, I can decide which one I want to plot, with this function:
function popupmenu1_Callback(hObject, eventdata, handles)
str = get(hObject, 'String');
val = get(hObject,'Value');
% Set current data to the selected data set.
switch str{val};
case 'plot1'
axes(handles.plot)
plot(x1,y1);
case 'plot2'
axes(handles.plot)
plot(x2,y2);
end
guidata(hObject,handles)
but what if I want to use a push button whose action depends on the string appearing in the popup menu? For example, if I have a pushbutton 'Linear fit' whose callback function makes a linear fit of the plot, how can I distinguish here the two cases of the popup menu? Thanks
0 commentaires
Réponse acceptée
Geoff Hayes
le 28 Jan 2015
aurc89 - in your push button callback, use the handles structure to refer back to your popup menu object named popupmenu1. For example,
function pushbutton1_Callback(hObject,eventdata,handles)
str = get(handles.popupmenu1, 'String');
val = get(handles.popupmenu1,'Value');
% etc.
Note that you may not need to get the string values back and can just use the integer val instead. (Also, in your popup menu callback, there is no need for the guidata(hObject,handles) because you haven't updated the handles structure..unless you haven't shown all of your code.) Try the above and see what happens!
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output 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!