首页 文章

MATLAB GUIDE错误:引用不存在的字段

提问于
浏览
0

在Matlab的GUIDE中,我尝试使用choose_data_button首次选择该文件时,使用数据文件的 Headers 动态更改弹出菜单的文本 . 但是,它给了我一个错误,即group_variable_popupmenu是一个不存在的字段 .

这篇文章可能有我的问题的答案,但我不会继续:MATLAB GUI error Reference to non-existent field '---'

% --- Executes on button press in choose_data_button.
function choose_data_button_Callback(hObject, eventdata, handles)
    % hObject    handle to choose_data_button (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

    [filename, pathname] = uigetfile( ... );
    set(handles.patient_data_file, 'string', fullfile(pathname,filename));

    data = csvimport(fullfile(pathname, filename));
    %%%%% ERROR (Reference to non-existent field 'group_variable_popupmenu'.):
    set(handles.group_variable_popupmenu, 'string', data(1,:));


% --- Executes on selection change in group_variable_popupmenu.
function group_variable_popupmenu_Callback(hObject, eventdata, handles)
    % hObject    handle to group_variable_popupmenu (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)

% --- Executes during object creation, after setting all properties.
function group_variable_popupmenu_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to group_variable_popupmenu (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called

    if ispc && isequal(get(hObject,'BackgroundColor'),                                 
        get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end

使用GUIDATA而不是get / set是一个更好的选择吗? GUIDE和Matlab的新手,所以任何解释都会非常有用 .

编辑 - 完整的错误消息:

Reference to non-existent field 'group_variable_popupmenu'.

Error in mockup>choose_data_button_Callback (line 148)
set(handles.group_variable_popupmenu, 'string', data(1,:));

Error in gui_mainfcn (line 95)
    feval(varargin{:});

Error in mockup (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)mockup('choose_data_button_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating UIControl Callback

2 回答

  • 0

    我最近在我的一个代码中也遇到了一些关于此错误的问题,我遇到了与找到合适答案相同的麻烦,我最后才发现这个问题 .

    我的问题是,一旦我输入了一个回调函数,它就找不到我的一个人的字段 .

    我找到的解决方案是在回调函数中移动我的数字的创建,而不是在外部 .

    也许尝试通过在回调函数的开头移动弹出菜单创建来做同样的事情,或者沿着线条移动 .

  • 0

    这可能是微不足道的,但您是从指南或命令窗口运行GUI图吗?我一开始多次犯的一个错误就是双击文件夹菜单中的.fig文件(不调用构造函数),而不是通过输入.fig文件的名称从命令窗口调用它(或者通过指南,作为替代) .

相关问题