Re: Guide: how to call a function




"Tomas " <tomasnic@xxxxxxxxx> wrote in message
news:hdh0op$oj6$1@xxxxxxxxxxxxxxxxxxxxx
I?m currently learning Guide and are wondering how you can call a function
from the GUI I created.

When I push a button I simply want to execute a function (called
myfunction):

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
res = myfunction;

guidata(hObject, handles);

I then get the error:

??? Error using ==> guidata at 89
H must be the handle to a figure or figure descendent.

*snip*

Am I too naive thinking its that easy to call a "selfmade" function?

If you read the error message, you'll see that it occurs in the call to
GUIDATA, which is _after_ your function call in your callback. The callback
has already executed your "selfmade function" when it errors -- likely
something else is causing the error.

Set a breakpoint on this line and run the callback using the pushbutton,
then check to make sure that hObject is in fact the handle of the button
whose callback is being executed and that the button has a figure as its
ancestor (you can use the ANCESTOR function to do so.) If it doesn't, you
need to determine why -- did you modify the Callback property of the button
and make it so the first input argument it receives is not the handle to the
button itself? Did your myfunction do something with EVALIN or ASSIGNIN
that changes the value of hObject? Did you close the figure between the
time the callback started to execute and when it attempted to update the
GUIDATA?

--
Steve Lord
slord@xxxxxxxxxxxxx
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


.



Relevant Pages

  • Re: [patch 1/7] Immediate Values - Architecture Independent Code
    ... static unsigned int stopmachine_num_threads; ... * help our sisters onto their CPUs. ... all the other CPUs will execute the callback concurrently. ...
    (Linux-Kernel)
  • Re: Sockets Beginreceive not working correctly.
    ... the beginrecieve is ignored. ... there's no reason to expect your callback method to be ... BeginReceivewould not normally execute the callback in any case. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How can I tell if my Ribbon is visible?
    ... Depending on the performance cost of executing the callback, you could do this whenever your event gets triggered, but before you execute your parsing. ... The callback will be executed once your tab is brought into the foreground. ... You can do this approach with any of your controls and callbacks, there is no need to create a special one for it. ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Sockets Beginreceive not working correctly.
    ... -- By the time you get to stepping through the code, the second part of your data hasn't yet been sent. ... there's no reason to expect your callback method to be executed. ... BeginReceivewould not normally execute the callback in any case. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: calling callback from function
    ... you should replace hObject with the handle to the GUI that you want to update. ... function is at the end of each callback. ... Since the hObject variable in the secondry callback has the value of ...
    (comp.soft-sys.matlab)