How can I get a Zoom In/Out value for a figure in MATLAB?
22 次查看(过去 30 天)
显示 更早的评论
Hello all.
I have a script that automatically moves through a video file frame by frame. At each frame, I manually click on any pixel in the figure and MATLAB record the coordinates of the selected pixel and moves automatically to the next frame.
The problem is when I zoom in at any frame, I lose the zooming when MATLAB moves to the next frame, and I have to zoom manually at each frame, which is impractical in my application.
Therefore, I am looking for a zooming function/object that can record the current zoom and so I can carry it to the following frame. The zoom object in MATLAB doesn't have the ability to get the current value/factor of the zoom.
Can anyone help with workarounds?
Thanks all.
采纳的回答
Walter Roberson
2022-9-20
You are using imagesc() in a loop. You do not have hold turned on, and you have not configured the axes NextPlot behaviour.
In such a situation, each time you imagesc(), the code for imagesc() internally calls nextplot, which looks at the axes NextPlot property. The default for that property is 'replace' -- which deletes all axes children and resets all axes properties except the Units and Positions properties. That includes clearing any Xlim, Ylim, and any internal recordings of zoom levels.
If you were to
set(gca, 'NextPlot', 'replacechildren')
then it would delete the children but the only axes properties it would reset would be the ColorOrderIdx and LineStyleOrderIdx properties -- so it would preserve the zoom level.
But an even better way of handling this situation would be to first, before the loop, do
h = imagesc();
and then inside the loop, delete the imagesc() and replace it with
h.CData = Data;
That will not change any axes properties (except possibly xlim and ylim and ticks if the image is a different size). And it is more efficient.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!