Help with pop up menu in a GUI interface
조회 수: 7 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!