Pressing the button changes position only once

I have a question about callback functions in MATLAB GUIDE. When the button is clicked, the following code is executed:

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 form still exists, but that's a separate issue). I ran the debug code and determined that the callback function is always called when the button is pressed, but for some strange reason there is no effect in changing the position after the first button click.

What am I doing wrong here?

+3


source to share


1 answer


You must update your descriptors with guidata

to take into account the changes handles

:

guidata(hObject,handles);

      



Otherwise, the changes handles

are lost at the end of the callback execution.

The best

0


source







All Articles