How to set the axes limits within a GUI

I can plot to a figure and set the axis with the command:
axis([0 900 -1 1])
I want to do the same for a set of axes within my GUI. I can't seem to figure this one out, any suggestions?

 Réponse acceptée

Matt Fig
Matt Fig le 6 Mai 2011
You probably need to find the handle to the axes object.
Ax = findall(0,'type','axes')
axis(Ax,[-1 1 -4 4])
Assuming this is GUIDE GUI...
What you left out is from where it is that you are trying to set the limits. If it is from within a callback, you should be able to access the axes handle by using the handles structure. If you are doing it from the command line, then the above will work.
Notice, however, that if you have a legend on the axes, Ax will contain two handles. In that case you will have to perform further tests to see which one is the correct handle. To avoid this you could give the axes a tag, then use the tag when searching with FINDALL.
%
%
%
EDIT In response to your 'answer' below.
Please put comments on answers in the comments, don't start another 'answer'.
So put this in your callback and show what dumps to the screen when you execute the callback:
findall(0,'type','axes')
handles.axes2
Also, are there other plotting commands executed after you change the limits? I.e., do you call PLOT, LINE, PATCH, or any function which interacts with the axes? The call to AXIS should be the last thing you do with the axes...

4 commentaires

b
b le 6 Mai 2011
I am trying to set the limits from within my own function in the GUIDE generated .m file. I tried this
axis(handles.axes2,[0 900 -1 1])
but no luck
---------------
This is what dumped:
ans =
1.0e+003 *
1.2280
1.0450
ans =
1.0450e+003
b
b le 6 Mai 2011
The only command I have after changing the limits is drawnow
Matt Fig
Matt Fig le 6 Mai 2011
O.k., so now do you call any other plotting type functions after the call to AXIS? See if you can change the limits by doing this from the command line:
Ax = findall(0,'type','axes')
axis(Ax(2),[0 900 -1 1]) % Now we know which is axes2
b
b le 6 Mai 2011
i got it! thanks a ton!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by