2009-04-25 2 views
1

私は2つのuicontrolオブジェクトを含むMATLAB GUIを作成しています。押しボタンとリストボックスです。私はリストボックスにファイル名を追加するために押しボタンを使います。 GUIをm-ファイルから実行するとうまく動作します。この問題は、.figファイル自体を実行した場合にのみ発生します。ここでは、コールバック・コードとエラーは次のとおりです。GUIDEを使用したMATLAB GUI:リストボックスの問題

function add_file_Callback(hObject, eventdata, handles) 
% hObject handle to add_file (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
%gets input file(s) from user 

[input_file,pathname] = uigetfile(... 
     {'*.jpg;*.tif;*.png;*.gif;*.bmp;*.pgm'}, ... 
     'Select files', ... 
     'MultiSelect', 'on'); 

%if file selection is cancelled, pathname should be zero 
%and nothing should happen 
if pathname == 0 
    return 
end 

%gets the current data file names inside the listbox 

inputFileNames = get(handles.img_list,'String'); 

%if they only select one file, then the data will not be a cell 
%if more than one file selected at once, 
%then the data is stored inside a cell 
if iscell(input_file) == 0 

    %add the most recent data file selected to the cell containing 
    %all the data file names 
    inputFileNames{end+1} = input_file; 

%else, data will be in cell format 
else 
    %stores full file path into inputFileNames 
    for n = 1:length(input_file) 
     %notice the use of {}, because we are dealing with a cell here! 
     inputFileNames{end+1} = input_file{n}; 
    end 
end 

%updates the gui to display all filenames in the listbox 
set(handles.img_list,'String',inputFileNames); 

%make sure first file is always selected so it doesn't go out of range 
%the GUI will break if this value is out of range 
set(handles.img_list,'Value',1); 

% Update handles structure 
guidata(hObject, handles); 

エラー:

Error in ==> Texture_Classification_GUI>add_file_Callback at 154 
inputFileNames = get(handles.img_list,'String'); 

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

Error in ==> Texture_Classification_GUI at 42 
    gui_mainfcn(gui_State, varargin{:}); 

??? Error using ==> Texture_Classification_GUI('add_file_Callback',gcbo,[],guidata(gcbo)) 
Attempt to reference field of non-structure array. 

??? Error while evaluating uicontrol Callback 

任意の助けもいただければ幸いです。

+0

私は、リストボックスを使用する前に初期化する必要があると考えていますが、私はどのように考えているのでしょうか。 –

答えて

5

figファイル自体を実行していますか?」とはどういう意味ですか? GUIDEは、m-file.figという2つのファイルを作成します(たとえば、my_guide_app.mmy_guide_app.fig)。 openfigのようなもので.figを開いていますか? m-fileは、ハンドル構造を作成する図形を開く関数を設定する必要があるため、これは機能しません。 GUIDEでGUIを実行するにはm-fileに電話をかけて、.figファイルを開くだけでなく、アプリケーションを起動する必要があります。

.figファイルの開封に関する記述を誤解した場合は、何か間違っている可能性があるので教えてください。

1

リストボックスは、GUIDEで初期化する必要があります。 1つのオプションで初期化するとchar配列になり、2つ以上のオプションで初期化するとセル配列になります。だから、そこに同様の小切手を入れなければなりません(iscell)。新しいオプションを追加します。

関連する問題