GUI handles problem

9 views (last 30 days)
Jason
Jason on 22 Feb 2011
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
Walter Roberson
Walter Roberson on 22 Feb 2011
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
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 Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!