Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Keeping the same zoom status when displaying different matrix on the same axe

Subject: Keeping the same zoom status when displaying different matrix on the same axe

From: Camille Couzi

Date: 25 Aug, 2010 19:50:22

Message: 1 of 5

Hi everybody,
I need your help on something, I can't find the solution on the web or in the help of matlab...
I am working on a GUI that have a axes and a uibuttongroup with 5 buttons. each button corresponds with a matriz, that are all the same size, but with different values inside.
I have created a SelectionChangeFcn for the uibuttongroup, so that each time I click on one button, it displays the matriz with an imagesc on the axes.

The thing is that if I select button1, it displays my matrix1, then I make (for example) a zoom in, and I would like to be able to click on the button2, and keep the same zoom I had made before - for the moment, as I have defined the SelectionChangeFcn, axes displays the entire matrix, so I can't keep the same zoom...

I have tried something identifying the xlim and ylim before writing the plot command, but it doesn't work properly.

Has someone an idea?

Thanks a lot in advance...


Camille.

Subject: Keeping the same zoom status when displaying different matrix on the same axe

From: Pekka Kumpulainen

Date: 26 Aug, 2010 10:16:05

Message: 2 of 5

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i53s5t$84t$1@fred.mathworks.com>...
> Hi everybody,
> I need your help on something, I can't find the solution on the web or in the help of matlab...
> I am working on a GUI that have a axes and a uibuttongroup with 5 buttons. each button corresponds with a matriz, that are all the same size, but with different values inside.
> I have created a SelectionChangeFcn for the uibuttongroup, so that each time I click on one button, it displays the matriz with an imagesc on the axes.
>
> The thing is that if I select button1, it displays my matrix1, then I make (for example) a zoom in, and I would like to be able to click on the button2, and keep the same zoom I had made before - for the moment, as I have defined the SelectionChangeFcn, axes displays the entire matrix, so I can't keep the same zoom...
>
> I have tried something identifying the xlim and ylim before writing the plot command, but it doesn't work properly.
>
> Has someone an idea?
>
> Thanks a lot in advance...
>
>
> Camille.

Getting the XLim and YLim after zooming and resetting to these values after the new plot should work. Provided you have them saved somewhere accessible to the function that makes the new plot.
Anyway, you could try setting the 'Nextplot' property of the axes object to 'replacechildren'. That should keep the limits as they were.

Subject: Keeping the same zoom status when displaying different matrix on the same axe

From: Camille Couzi

Date: 26 Aug, 2010 17:50:32

Message: 3 of 5

"Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <i55et5$sb1$1@fred.mathworks.com>...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i53s5t$84t$1@fred.mathworks.com>...
> > Hi everybody,
> > I need your help on something, I can't find the solution on the web or in the help of matlab...
> > I am working on a GUI that have a axes and a uibuttongroup with 5 buttons. each button corresponds with a matriz, that are all the same size, but with different values inside.
> > I have created a SelectionChangeFcn for the uibuttongroup, so that each time I click on one button, it displays the matriz with an imagesc on the axes.
> >
> > The thing is that if I select button1, it displays my matrix1, then I make (for example) a zoom in, and I would like to be able to click on the button2, and keep the same zoom I had made before - for the moment, as I have defined the SelectionChangeFcn, axes displays the entire matrix, so I can't keep the same zoom...
> >
> > I have tried something identifying the xlim and ylim before writing the plot command, but it doesn't work properly.
> >
> > Has someone an idea?
> >
> > Thanks a lot in advance...
> >
> >
> > Camille.
>
> Getting the XLim and YLim after zooming and resetting to these values after the new plot should work. Provided you have them saved somewhere accessible to the function that makes the new plot.
> Anyway, you could try setting the 'Nextplot' property of the axes object to 'replacechildren'. That should keep the limits as they were.

Hi Pekka,
Thanks a lot for your answer,
I have tried to include the 'nexplot' property, set to 'replacechildren'. It seem to work, unless a little inconvenient: it doesn't plot correctly the entire image, and zoom out and pan don't work.
is there a way to set this 'nexplot' property on 'replacechildren', but keeping the original way of drawing the plot?
In the axes properties page they say: "replacechildren — Remove all child objects, but do not reset axes properties (equivalent to cla)."
and in fact, in cla page:c "la deletes from the current axes all graphics objects whose handles are not hidden (i.e., their HandleVisibility property is set to on)."...

If you can help me a little bit more that would be great
Thanks again

Camille.

Subject: Keeping the same zoom status when displaying different matrix on the same axe

From: Pekka Kumpulainen

Date: 27 Aug, 2010 05:57:05

Message: 4 of 5

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i569h8$j5a$1@fred.mathworks.com>...
> "Pekka Kumpulainen" <pekka.nospam.kumpulainen@tut.please.fi> wrote in message <i55et5$sb1$1@fred.mathworks.com>...
> > "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i53s5t$84t$1@fred.mathworks.com>...
> > > Hi everybody,
> > > I need your help on something, I can't find the solution on the web or in the help of matlab...
> > > I am working on a GUI that have a axes and a uibuttongroup with 5 buttons. each button corresponds with a matriz, that are all the same size, but with different values inside.
> > > I have created a SelectionChangeFcn for the uibuttongroup, so that each time I click on one button, it displays the matriz with an imagesc on the axes.
> > >
> > > The thing is that if I select button1, it displays my matrix1, then I make (for example) a zoom in, and I would like to be able to click on the button2, and keep the same zoom I had made before - for the moment, as I have defined the SelectionChangeFcn, axes displays the entire matrix, so I can't keep the same zoom...
> > >
> > > I have tried something identifying the xlim and ylim before writing the plot command, but it doesn't work properly.
> > >
> > > Has someone an idea?
> > >
> > > Thanks a lot in advance...
> > >
> > >
> > > Camille.
> >
> > Getting the XLim and YLim after zooming and resetting to these values after the new plot should work. Provided you have them saved somewhere accessible to the function that makes the new plot.
> > Anyway, you could try setting the 'Nextplot' property of the axes object to 'replacechildren'. That should keep the limits as they were.
>
> Hi Pekka,
> Thanks a lot for your answer,
> I have tried to include the 'nexplot' property, set to 'replacechildren'. It seem to work, unless a little inconvenient: it doesn't plot correctly the entire image, and zoom out and pan don't work.
> is there a way to set this 'nexplot' property on 'replacechildren', but keeping the original way of drawing the plot?
> In the axes properties page they say: "replacechildren — Remove all child objects, but do not reset axes properties (equivalent to cla)."
> and in fact, in cla page:c "la deletes from the current axes all graphics objects whose handles are not hidden (i.e., their HandleVisibility property is set to on)."...
>
> If you can help me a little bit more that would be great
> Thanks again
>
> Camille.

You told in the beginning that you use imagesc to make the plots, right?
This is what I tried
figure; ha = axes('Nextplot','replacechildren');
imagesc(randn(64))
% zoom in
 imagesc(peaks(64))
% the limits are the same that I zoomed in
% both zoom out and pan do work
If they don't work for you, there must be something else going on with your plots.
Or I misunderstood what you really wanted.

Subject: Keeping the same zoom status when displaying different matrix on the same axe

From: Camille Couzi

Date: 27 Aug, 2010 15:11:10

Message: 5 of 5

Hi Pekka!
Thanks for your reply. In fact, I discovered that I had this problem because I at the beginning, I put the 'nextplot','replacechildren' just after having defined my axis, in the script that contained all the button and panels definition, like that:
h.cp1=subplot(5,3,[1 2 4 5],'Parent',h.panel_contourplots);
set(h.cp1,'position',[0.08 0.7 0.5 0.25] );
set(h.cp1,'nextplot','replacechildren');

And as it was not working like that, I begun moving that property setting to another places, and finally, the plot work fine if I put that property setting after the imagesc command (which is in another function 'plot_imagesc.m':
imagesc(matriz);
... (other commands)
set(h.cp1,'nextplot','replacechildren');

I don't know why exactly that works ok when writen in that order, but .. that works!!!

Thank you very much again for your replies...
Hope that would help people in same situations in the future! :-)

Saludos desde Chile!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us