Callback function in guide

Hello guys, I made a GUI by making use of 'guide'. My GUI make cell array named 'shapes' when pushbutton51 is pressed, Then the 'newshapecreated' is triggered(I made this as a callback function) And this callback function should process with the 'shape'. But it can't read the 'shape'. The matlab says 'Input argument "handles" is undefined.'
What is the problem with my code?
*function pushbutton51_Callback(hObject, eventdata, handles)
shapes = {};
handles.shapes = shapes;
guidata(hObject, handles);
% below is callback function newshapecreated;
function newshapecreated(hObject, eventdata, handles)
shapes=handles.shapes;*

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 9 de Jun. de 2013

0 votos

The second function should be
function newshapecreated(hObject, eventdata, handles)
shapes=handles.shapes

7 comentarios

Seombeom Kim
Seombeom Kim el 9 de Jun. de 2013
Sorry, Azzi Abdelmalek. Your right. It was my mistake to write code at question. I ran the code exactly you suggested. But it still says 'Input argument "handles" is undefined.'
Azzi Abdelmalek
Azzi Abdelmalek el 9 de Jun. de 2013
What is
shapes = {};
Azzi Abdelmalek
Azzi Abdelmalek el 9 de Jun. de 2013
Maybe, you should make some initialization in opening function
Seombeom Kim
Seombeom Kim el 9 de Jun. de 2013
Mmm. Yes. Like you said, Actually I made shapes = {}; in opening function.
In pushbutton51 code will add some data into 'shape', like shape{end+1} = something; And I want this 'shape' to be saved and trigger the newshapecreated. This newshapecreated function will process with updated 'shape'.
I saved 'shape' as handle.shape = shape
And want to read the 'shape' shape = handles.shape; in newshapecreated.
But it doesn't works! :(
Azzi Abdelmalek
Azzi Abdelmalek el 9 de Jun. de 2013
Ok, how the function newshapecreated is triggered? and what represent this callback function?
Seombeom Kim
Seombeom Kim el 9 de Jun. de 2013
Editada: Azzi Abdelmalek el 9 de Jun. de 2013
% As I mentioned, shapes = {}; is pre-defined
% If I push button51,
function pushbutton51_Callback(hObject, eventdata, handles)
% Now shapes element will be added like below
% I presented 'someting', because real code is rather complicated. :(
shapes{end+1} = something;
% Save 'shapes'
handles.shapes = shapes;
guidata(hObject, handles);
% now trigger 'newshapecreated' function newshapecreated;
% So far, end of the pushbutton callback.
% below is callback function newshapecreated;
function newshapecreated(hObject, eventdata, handles)
shapes=handles.shapes;
% From now on I have to make process with 'shapes'.
% but matlab insists 'Input argument "handles" is undefined.'
% So far, I have had no problem with 'handles.blah'. But what is the problem in this case?
Seombeom Kim
Seombeom Kim el 9 de Jun. de 2013
I solved problem!
simply I added like below.
function newshapecreated(hObject, eventdata, handles)
handles = guidata(gcbo);
shapes=handles.shapes;
Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Jun. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by