Matlab GUI popup menu
2 次查看(过去 30 天)
显示 更早的评论
Hi I'm new to GUI so sorry if it's so obvious.
I want to use a popup menu to select which dataset to load in my program. In the popup menu it simply says Dataset-1 and Dataset-2 for contents. I use following:
function popup_selectds_Callback(hObject, eventdata, handles)
a=get(handles.popup_selectds,'value');
switch a
case 1
load('dataset.mat')
case 2
load('dataset2.mat')
end
guidata(hObject, handles);
It does not give any errors and when I debug it it works but it does not work when I do in on the GUI. What's wrong with it?
Thank you.
1 个评论
Geoff Hayes
2015-1-8
Ege - It isn't obvious to me what is wrong with your code. In fact, if I copy and paste it into a sample GUI, then the correct case is executed given the selection in the popup menu.
As an aside, you could try replacing
a=get(handles.popup_selectds,'value');
with
a=get(hObject,'value');
as hObject will also be the handle to the popup (and should be identical to handles.popup_selectds).
Also, are you sure that the popup_selectds_Callback will fire? Is the name/tag of your popup menu still popup_selectds?
回答(1 个)
Image Analyst
2015-1-8
When you call load(), it "poofs" the variables into the workspace of the function. When that function exits, all those variables are lost. If you want to retain them, so that you can use them outside the callback function, you'll have to make them global, or attach them to a new field(s) that you create on the handles structure. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!