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

 채택된 답변

Jason
Jason 2011년 2월 22일

0 개 추천

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

Matt Tearle
Matt Tearle 2011년 2월 22일
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 2011년 2월 22일
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 2011년 2월 22일
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 2011년 2월 22일
That's odd. Can you show the old code? I have no problem doing something like
axes(h)
imshow('foo.jpg')
Walter Roberson
Walter Roberson 2011년 2월 22일
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 2011년 2월 22일
Walter - you are a star, thats exactly the problem, I did have hold on. Thankyou very much and for the advice over handles.axes1.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Tearle
Matt Tearle 2011년 2월 22일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2011년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by