Find axes callback on which zoom is performed

16 views (last 30 days)
Rakshitha
Rakshitha on 16 Aug 2014
Answered: Tracy on 22 Mar 2017
Hi, Am trying to implement zoom by clicking and dragging on the axes to create a box.Only the part of the axes inside the box should be zoomed. I am planning to do this by getting the coordinates by (waitforbuttonpress).As I have multiple axes on GUI am not able to get the handle of that particular axes on which zoom is performed(I further want to perform some calculations on the data by the coordinates obtained and plot back the data on another axes which is right besides the axes on which the zoom is performed).For this I need to detect the axes on which zoom is performed i.e.,I need to find the axes handles.
Thanks in advance!!
function uitoggletool1_ClickedCallback(hObject, eventdata, handles)%zoom callback
before=get(gca,'Tag')%here I get present axes handle
k = waitforbuttonpress;
after=get(gca,'Tag')%handle is lost here(this call back is for the axes on which zoom is performed)

Answers (2)

Adam
Adam on 16 Aug 2014
Edited: Adam on 16 Aug 2014
Can you not just use the axes' ButtonDownFcn callback to trigger your zooming behaviour? Then the axes handle that triggered the callback will be one of the callback's arguments.
If you have many axes on which you want this behaviour you can point them all to the same callback.
This would also avoid what I would think to be the problem otherwise of pressing a button not on any axes, though I guess if you are happy to just expect the person using the tool to not do that then that isn't a problem
  2 Comments
Rakshitha
Rakshitha on 18 Aug 2014
Thanks a lot for your reply Adam! Could you please elaborate? Whats the alternative for 'ButtonDownFcn'? Can I have different zoom funtions for different axes(using one zoom button)?If so how can I do it?
Adam
Adam on 18 Aug 2014
You should be able to use the ButtonDownFcn callback for each of your axes (you can have a callback for each or assign them all to the same callback) in which you store the axes handle that triggered the callback (hObject) on the GUI handles structure (remember to use guidata( hObject, handles ) afterwards.
Then you can set the Figure's (note, this is a figure callback, not an axes callback so you will need the main figure handle to set this):
WindowButtonUpFcn
to a callback which will trigger when you then release the mouse button (end dragging). In that callback you can retrieve the axes handle (that triggered the ButtonDownFcn callback) from your handles structure and do whatever zooming behaviour you wish.
At the end of that function be sure to set WindowButtonUpFcn back to [] though so that it won't trigger unexpectedly later on.

Sign in to comment.


Tracy
Tracy on 22 Mar 2017
Just had the same problem and finally figured it out.
%Create a zoom handle and define the post-callback process
handles.zhndl = zoom;
handles.zhndl.ActionPostCallback = {@zoomMapAspect,handles};
%Post-callback function
function zoomMapAspect(curfig, curax, handles)
% curfig handle to current figure
% curax reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if curax.Axes==handles.axis1 % Test if this is the axis you want
% Do something here
end

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!