当我尝试在非回调函数内访问句柄结构的数据成员时,它给出了“引用不存在的字段...”错误。或者你只能在matlab gui编程中使用回调函数内的句柄结构?
答案 0 :(得分:0)
如果要在随机函数中使用句柄,则必须使用以下内容:
handles = guidata(hObject);
这允许您“加载”句柄结构,并且hOject
是句柄的位置,请确保在您使用参数编写的函数中传递此变量:
function [var_out] = my_function(var_in,hObject,handles)
handles=guidata(hObject);
%some code
guidata(hObject,handles);
end;
如果要“保存”使用句柄结构完成的所有操作,最后一行非常有用。 这样,您就可以在非回调函数中使用句柄结构:
function my_callback(hObject,eventdata,handles)
%some code
[var_out] = my_function(var_in,hObject,handles);
end
如果您在回调中拨打my_function
,这一切都有效。