フィルターのクリア

Matlab GUI popup menu

1 回表示 (過去 30 日間)
Ege
Ege 2015 年 1 月 5 日
回答済み: Image Analyst 2015 年 1 月 8 日
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
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
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

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by