MATLAB GUI使用GUIDE:列表框问题

1 matlab user-interface listbox button matlab-guide

我正在创建一个包含两个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);
Run Code Online (Sandbox Code Playgroud)

错误:

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
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

Azi*_*zim 5

" 运行无花果文件本身 " 是什么意思?GUIDE创建两个文件:an m-file和a .fig文件(例如my_guide_app.mmy_guide_app.fig).你打开这样的.fig东西openfig吗?这不起作用,因为m-file需要设置数字打开功能,从而创建句柄结构.因此,要运行使用GUIDE制作的GUI,必须调用m-file启动应用程序,而不是仅打开.fig文件.

如果我误解了你关于打开.fig文件的声明,请告诉我,因为可能还有其他错误.