フィルターのクリア

Help with pop up menu in a GUI interface

2 ビュー (過去 30 日間)
aurc89
aurc89 2015 年 1 月 28 日
回答済み: Geoff Hayes 2015 年 1 月 28 日
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

採用された回答

Geoff Hayes
Geoff Hayes 2015 年 1 月 28 日
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 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by