How to display values of axes after zooming in GUI at the moment of zooming

2 views (last 30 days)
Dear all, I'm struggling with zooming in in my GUI. I have an image and it's important for a user to be able to have the exact values of XLims after zooming in. I created an edit text field where this information is displayed ("Phase values"), but by far I only managed to have these values displayed after I press again on my Zoom In button.
My question is: how to code it to have these values in my text field at the moment of zooming ?
Here is a part of code which I use:
function ZoomBtn_Callback(hObject, eventdata, handles)
zoom(handles.Plot1_ax)
displayZoomXLims_txt(handles)
function displayZoomXLims_txt(handles)
XLims_values = sprintf(' %s ', num2str(handles.Plot1_ax.XLim(1)), num2str(handles.Plot1_ax.XLim(2)));
set(handles.XLims_txt, 'String', XLims_values);
Thank you in advance for any tips.
I attach an image how it looks like.
  2 Comments
Adam
Adam on 24 Jul 2018
Edited: Adam on 24 Jul 2018
If you look at
doc zoom
there is a section on the ActionPostCallback which should work for what you want.
e.g.
zoomInfo = zoom( hFig );
zoomInfo.ActionPostCallback = @( ) displayZoomXLims_txt(handles);
or something similar, where hFig is your figure handle
A. Wozniak
A. Wozniak on 24 Jul 2018
Thank you Adam. Yes, I dug in the zoom doc and found a solution. This works perfectly (for anyone who can have the same problem in future):
function ZoomBtn_Callback(hObject, eventdata, handles)
h = zoom(handles.Plot1_ax);
set(h, 'ActionPostCallback', @zoom_callback);
% h.ActionPostCallback = @zoom_callback;
h.Enable = 'on';
zoom_handl = guidata(handles.Plot1_ax); % pass all handles to zoom_callback function
guidata(handles.Plot1_ax, zoom_handl); % pass all handles to zoom_callback function
function zoom_callback(hObject, eventdata)
newLimX = eventdata.Axes.XLim;
newLimY = eventdata.Axes.YLim;
XLims_values = sprintf('[%.1f %.1f] Hz', newLimX);
YLims_values = sprintf('[%.1f %.1f] Hz', newLimY);
fprintf('New phase values: [%.1f %.1f] \n', newLimX);
fprintf('New amplitude values: [%.1f %.1f] \n', newLimY);
h = guidata(hObject); % get the handles of the maingui
set(h.XLims_txt, 'String', XLims_values);
set(h.YLims_txt, 'String', YLims_values);

Sign in to comment.

Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!