MATLAB: How to set the axes limits within a GUI

plot with 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?

Best Answer

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...