GUI handles problem

I have a GUI created in Guide where I create for axes (axes 1..axes4).
I want to plot data on these axes from another function defined in a seperate .m file. I thought I only hat to include "handles" as an argument to pass. In my seperate function where I want to plot to these axes, I use:
axes(handles.axes1)
plot(X,Y)
But I get an error
??? Error using ==> axes
Invalid object handle
Any suggestions to what I am doing wrong Thanks. Jason

 Accepted Answer

Jason
Jason on 22 Feb 2011
Hi Matt. I am using the GUIDE interface to select a certain image. I also include an axes component from the GUIDE palette. I tehn run a seperate m file to perform image analysis and this calculates certain properties of the image i.e. average FWHM and SNR etc. I then want to take these values and plot them on the original axes component I created in GUIDE.
I have searched the net for a day and thought you only have to pass the handles structure as an argument. Once this is done, I can then access the AXES component and plot to it by:
axes(handles.axes1) //select component to plot to
plot(X,Y) //plot to it
Seems like Im missing something and am at a loss!

6 Comments

Matt Tearle
Matt Tearle on 22 Feb 2011
When you say that you "run a separate file" to do the analysis, what *exactly* do you mean? Do you enter something at the command line, or is this called via some GUI interaction, or is just called as a function from the GUI code (with no interactive event to trigger it)? This is the critical component. Can you show the exact code you use to invoke the function that's giving the error message?
Matt Tearle
Matt Tearle on 22 Feb 2011
Actually, add a simple diagnostic: can you add the lines
whos handles
fieldnames(handles)
get(handles.axes1)
prior to the axes() command and post the result. Thanks
Jason
Jason on 22 Feb 2011
OOK, it seems the following does now work. Make sure the handles is passed as an argument, and then :
axes(handles.axes1)
plot(s(a,1),s(a,3)/1000,'k.')
I noticed I had another graphics (using imshow) in the same location. Once I deleted this imshow command it all worked for some reason.
I don't understand why, does anyone?
Thanks
Matt Tearle
Matt Tearle on 22 Feb 2011
That's odd. Can you show the old code? I have no problem doing something like
axes(h)
imshow('foo.jpg')
Jason, sounds like you might have had "hold on" on the axes.
I suggest, by the way, using this approach:
ax = handles.axes1;
plot(ax, s(a,1),s(a,3)/1000,'k.');
without using axes() to make the axes the "current" axes. I recommend this approach of explicitly specifying the axes in the call because there are circumstances under which the "current axes" can change unexpectedly... especially while you are debugging.
Jason
Jason on 22 Feb 2011
Walter - you are a star, thats exactly the problem, I did have hold on. Thankyou very much and for the advice over handles.axes1.

Sign in to comment.

More Answers (1)

Matt Tearle
Matt Tearle on 22 Feb 2011

0 votes

It sounds like you're trying to refer to a local variable in a separate function. The GUI function created by GUIDE contains the structure variable handles, with a field called axis1. You need to pass that variable to your plotting function when you call it, but you have to do so from within the main GUI function, otherwise it won't recognize the variable. How is your plotting function being invoked? The typical way in a GUI is that some interaction with the GUI invokes a callback. GUIDE callbacks take three arguments by default, the second being the handles structure.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 22 Feb 2011

Community Treasure Hunt

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

Start Hunting!