3

I have a question about callback functions in MATLAB's GUIDE. I have the following code execute when a button is pushed:

handles.xPos=handles.xPos+1
addX = handles.xPos
handles.shape2 =fill ([-2+addX 1+addX 1+addX -1+addX], [1 1 -1 -1], 'r');

This works, but only once (and the old shape is still there, but that is a separate problem). I have done debugging code and have determined that the callback function is always called when the button is pushed, but for some strange reason there is no effect in the change of the position after the first push of the button.

What am I doing wrong here?

dsolimano
  • 8,870
  • 3
  • 48
  • 63

1 Answers1

0

You have to update your handles via guidata to take the modifications of handles into account:

guidata(hObject,handles);

Otherwise the modifications of handles are lost at the end of the callback's execution.

Best

Ratbert
  • 5,463
  • 2
  • 18
  • 37