Keep zoom in when displaying an image and zoom out after

9 ビュー (過去 30 日間)
Mathieu
Mathieu 2015 年 7 月 20 日
コメント済み: Mathieu 2015 年 7 月 21 日
Hello,
I am working on an interface using Guide on Matlab R2015a. What I would like is to be able to zoom in an image ploted on a figure of my gui, and then keeping my xlim and ylim when I display this image. I found how to do this getting the xlim and ylim of the figure juste before the display. What I have to do is set these limits to the new figure like this:
xlim = get(axes.handles, 'XLim');
display_image;
set(axes.handles, 'XLim', xlim);
But if I want to zoom out after, I can't because my axes are now the last ones (that I setted manually). Did I miss something to be able to zoom out after a zoom in and a display? I think it is just a little thing to know but I don't find.
Thank you in advance for your help.

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 20 日
displaying an image does not inherently change the active axes, but it could be that your display_image() code is written in such a way that it changes the active axes.
Do not write your code like
axes(handles.axes2)
image(TheImageArray);
instead write
image(TheImageArray, 'Parent', handles.axes2);
This does not change the active axes.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 7 月 20 日
Not the parent image, the parent axes. If you want it in a different figure and the only thing in that figure then you use
fig2 = figure(2); %or use appropriate number
ax2 = axes('Parent',fig2);
image(TheImageArray, 'Parent', ax2);
If zoom reset works for you then go ahead and use it this time. But in the long run when you develop more complex GUI you will find that relying on active figures or active axis doesn't work very well. If you rely on active axes or active figures then you cannot "just add a little plot to the code" without risking breaking your existing graphics structure. You will also find that there are a lot of different ways that a figure or axes can accidentally become active. Like debugging -- and if you aren't writing your program with the expectation that you will need to debug it, then you are not writing good code.
Mathieu
Mathieu 2015 年 7 月 21 日
Ok I thank you for your answer. I will try to use your method.
Best regards.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 7 月 20 日
Zooming an image is tricky. See the attached demo which I got from the Mathworks on how to use a "imscrollpanel".
  1 件のコメント
Mathieu
Mathieu 2015 年 7 月 20 日
I have not the toolbox with this function. It is why I am looking for another solution. What I didn't say is that my image is composed with vectors of data (like if I was watching these vectors by top). I keep in mind your function if one day I have the adequate toolbox.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by