0

GUIDEで作成したGUIからポップアップメニューを作成しようとしています。私は次のようにしています:

TestFiles = dir([pwd '/test/*.txt']);
TestList = [];

for i = 1:length(TestFiles)
    filename = TestFiles(i).name;
    TestList = [TestList filename];
end

set(handles.popup_test,'string',TestList);

私はこれをpopup_test_CreateFcnメソッド内で行っています(ただし、それが正しい場所かどうかはわかりません)。

GUIを起動しようとすると、次のようになります。

??? Attempt to reference field of non-structure array.

Error in ==> init>popup_test_CreateFcn at 101
set(handles.popup_test,'string',TestList);

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> init at 19
    gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)init('popup_test_CreateFcn',hObject,eventdata,guidata(hObject))


??? Error using ==> struct2handle
Error while evaluating uicontrol CreateFcn

そのため、何らかの理由で、このset()メソッドではポップアップメニューにTestListを入力できません。

何かご意見は?

前もって感謝します。

4

1 に答える 1

1

プログラムを実行すると、最初に呼び出される関数は"create functions"

したがって、set(handles.popup_test,'string',TestList);内部popup_test_CreateFcnで実行すると、関数handles"opening function". ( の中に印刷しようとする"create functions"と、空になります)。

この関数内で次のようなことができます。

handles.popup_test=hObject;  %pass handles the popup menu object
guidata(hObject, handles);

そして、オープニング関数でXXXX_OpeningFcn(hObject, eventdata, handles, varargin)追加できます:

%...define TestList and other things you need
set(handles.popup_test,'string',TestList);
于 2012-12-14T13:51:20.063 に答える