pass handle information to button down function
显示 更早的评论
I want to create a GUI, in which i plot a histogram into an axes. For this axes, I want a button down function to react in certain ways, depending on what bin of the histogram I am clicking at. I created the GUI with guide containing the axes 'handles.histo' and, through guide, made the histo_ButtonDownFcn(hObject, eventdata, handles) appear in the code.
function histo_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to histo (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%my added code that does certain things to other objects within this GUI
If i click on the axes itself, it works perfectly. But due to the problems that occur when it comes to adding the histogram, i need to additionally set histo_ButtonDownFcn as a ButtonDownFcn for the histogram h in the code.
axes(handles.histo);
h=imshow(myHistogram);
set(h,'ButtonDownFcn',@histo_ButtonDownFcn);
but for some reason, after adding this line, I don't have access to any handle anymore in the ButtonDownFcn, so if I would for instance like to change the string of some text field handles.text1 within the ButtonDownFcn
set(handles.text1,'String','newstring');
it would tell me:
Error using GUI_versuch_5>histo_ButtonDownFcn (line 108)
Not enough input arguments.
Error while evaluating image ButtonDownFcn
So it seems as if the input data (hObject, eventdata, handles) is not passed to the ButtonDownFcn anymore...
I would be grateful for any help or suggestions about how to solve this problem!
回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!