Why does the ButtonDownFcn callback of my axes object stop working after plotting something?

前端 未结 2 1887
忘掉有多难
忘掉有多难 2021-01-20 03:37

I\'m creating a set of axes in a figure and assigning a callback for its \'ButtonDownFcn\' property like so:

HRaxes = axes(\'Parent\', Figure, \         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 04:27

    @David Snyder, observe that an image object can have a ButtonDownFcn callback property as well. Then in your callback you can have access to the corresponding axes property throught Parent property or ancestor function. For instance, say you want to use in your ButtonDownFcn callback the position of the pixel and the button you clicked with. When you plot the image, use

    imh = image(some_image);
    set(imh,'ButtonDownFcn',@position_and_button);
    

    where you defined your callback somewhere else

    function position_and_button(hObject,eventdata)
       Position = get( ancestor(hObject,'axes'), 'CurrentPoint' );
       Button = get( ancestor(hObject,'figure'), 'SelectionType' );
       %# do stuff with Position and Button
    

提交回复
热议问题