Error while evaluating Axes ButtonDownFcn
显示 更早的评论
Im trying to making a ButtonDownFcn for one of my axes in a gui created in GUIDE. But due to my lack of knowledge I dont know which input arguments to use.
Main Code:
function hgui = saxsgui(varargin)
xyChildren = get(gui.xy_axes,'Children');
rthChildren = get(gui.rth_axes,'Children');
xyChildren.HitTest = 'off';
rthChildren.HitTest = 'off';
gui.rth_axes.ButtonDownFcn = {@zoomon_click};
gui.xy_axes.ButtonDownFcn = {@zoomon_click};
%The function for ButtonDownFcn.
function zoomon_click(handles, gui) %hObject,
%callback for zoom shortcut
% handles = guidata(hObject);
menu = findobj('Label','Zoom');
menu = findobj(menu,'tag','MenuViewZoom');
% set(gui.zoomoff_button,'Visible','on')
state = 'on';
zoom(gui.figure, state)
togglemenu(menu)
% guidata(hObject,handles);
Error message:
No appropriate method, property, or field 'figure' for class 'matlab.graphics.eventdata.Hit'.
Error while evaluating Axes ButtonDownFcn
3 个评论
Geoff Hayes
2018-6-21
Nikolaj - I don't understand your saxsgui function. You pass in a variable number of arguments but don't try to use anything and instead reference something called gui. How was this passed in to your function? This same function also returns (has an output parameter) hgui but this is never initialized. What is this for? Perhaps show how you call saxsgui from your main code.
As for the zoomon_click callback, the two input parameters are not the handles structure or the gui (?) but the handle to the source/object that caused the callback to fire (so the object that the callback is attached to) and some event data (if any exists). The signature should look more like
function zoomon_click(hObject, eventdata)
If you wish to pass additional parameters to this function (like the figure or GUI handle), then you would do this when you assign the callback
gui.rth_axes.ButtonDownFcn = {@zoomon_click, hGui};
and youd callback signature would become
function zoomon_click(hObject, eventdata, hGui)
The trick will be to pass the GUI handle into your saxsgui function...
is a callback function so your first 2 function inputs are passed by Matlab, namely hObject and event. Try to change it to
function zoomon_click(hObj,~,handles,gui)
It seems like you are using gui to pass handles instead of handles, maybe you can omit one of those.
edit: you need to change your callback to
{@zoomon_click,gui}
Nikolaj Daniel
2018-6-21
编辑:Nikolaj Daniel
2018-6-21
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!