Callback function in guide

1 次查看(过去 30 天)
Seombeom Kim
Seombeom Kim 2013-6-9
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;*

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-6-9
The second function should be
function newshapecreated(hObject, eventdata, handles)
shapes=handles.shapes
  7 个评论
Seombeom Kim
Seombeom Kim 2013-6-9
编辑:Azzi Abdelmalek 2013-6-9
% 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 2013-6-9
I solved problem!
simply I added like below.
function newshapecreated(hObject, eventdata, handles)
handles = guidata(gcbo);
shapes=handles.shapes;
Thanks!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by