MATLAB: How to delete an object in a plot using the delete button in keyboard

delete-figure

Hi all,
I want to delete an object I created in a plot using the delete button. I created a GUI with a plot plotting a figure as described by the following:
t = 0:pi/5:2*pi;
figure
patch(sin(t),cos(t),'y')
axis equal
Now how should I delete it using the delete button?
Thanks
Viv

Best Answer

Use the figure KeyPressFcn or WindowKeyPressFcn callback. Test the received key. If it is the delete character, then delete() the object handle.