1

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

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

どんな助けでも大歓迎です。

4

2 に答える 2

5

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

.fig他に何か問題がある可能性があるため、ファイルを開くことについてのあなたの声明を誤解した場合はお知らせください。

于 2009-04-25T17:09:58.173 に答える
1

Listbox は GUIDE で初期化する必要があると思います。1 つのオプションで初期化すると char 配列になり、2 つ以上のオプションで初期化すると cell 配列になります。したがって、同様のチェック (iscell) も行う必要があります。次に、新しいオプションを追加します。

于 2009-05-10T07:47:12.600 に答える