Hello,
I understand that you would like to be able to constrain the zoom in the y-dimension based on what data if currently in view. Probably the easiest way would be to create a callback for the zoom object that manually adjusts the y-limits based on the data. This documentation page is helpful in determining the format of the callback functions, and other zoom properties. Here is a quick example to demonstrate how to do exactly that:
function ZoomCallbackExample
x = 1:100;
y = rand(size(x));
y(5) = 5;
xEvents = 10:10:90;
yMin = min(y);
yMax = max(y);
hFig = figure;
plot(x,y,'-k')
hold on
for iEvent = 1:numel(xEvents)
plot([xEvents(iEvent) xEvents(iEvent)],[yMin yMax],'-r')
end
hold off
hZoom = zoom(hFig);
hZoom.Motion = 'horizontal';
hZoom.ActionPostCallback = @(obj,objEvent) afterZoom(obj,objEvent,x,y);
end
function afterZoom(~,objEvent,x,y)
hAx = objEvent.Axes;
yInView = y(x >= hAx.XLim(1) & x <= hAx.XLim(2));
hAx.YLim = [min(yInView) max(yInView)];
end
I hope this demonstrates the effect you are trying to achieve.
-Cam
Best Answer