title: Matlab GUI - Axes callback for mouseclick
body: <p>I am programming a GUI with matlab and somehow I have problems with the callbackfunction of a mouseclick on an axes. I found some similar topics but the solutions given there won't solve my problem.</p>
  
  <p>The important parts of my code look like this (first normal try with the ButtonDownFcn of the Axes, this works aslong as I dont plot anything):</p>
  
  <pre><code>function Axes_1_ButtonDownFcn(hObject, eventdata, handles)
  
  disp('axis callback');
  </code></pre>
  
  <p>(second try in which I wanted to turn HitTest off, this one doesn't work at all)</p>
  
  <pre><code> axes(handles.Axes_1); 
   h=plot(x,y);
   set(h,'HitTest','off');
   set(gcf,'WindowButtonDownFcn','disp(''axis callback'')')
   set(h,'ButtonDownFcn','disp(''axis callback'')')
  </code></pre>
  
  <p>Since I turned HitTest off I thought the click should work even with a plot on the axes but it doesn't. Any suggestions?</p>
  
  <p>Thank you! </p>
  
  <p>Klaus</p>
  
  <p>Update1: @matlabgui
  I tried to change NextPlot to add like in your example but it still doesn't work. I think at this point I'm not familiar enough with MATLAB/GUI to understand your suggestion properly.</p>
  
  <p>I hope this is not too much too ask for, but if I just created a ButtonDownFcn (empty) for the Axes itself and plot a graph like in the following code. What would I have to add to the code to display "Single click on axis" in my command window after I clicked on the axis in which the graph is displayed (no matter if I click on the empty space in the plot or the line itself)? I think it is easiest to have a short example which works in my code and then analyse this step by step.</p>
  
  <p>Code for plotting:</p>
  
  <pre><code>axes(handles.Axes_1); 
  plot(x,y);
  </code></pre>
  
  <p>empty bdfcn:</p>
  
  <pre><code>function Axes_1_ButtonDownFcn(hObject, eventdata, handles)
  </code></pre>