how to delete an object in a plot using the delete button in keyboard

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

댓글 수: 2

What do you want to delete? Do you want to delete the whole plot? Close the figure?
Why do you want to use the delete button? Why not close, or alt+F4?
Hi Mahdi, I want to delete the polygon object inside the plot and not the plot itself.
Thanks
Viv

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 26일

0 개 추천

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

댓글 수: 8

Hi Walter,
Can you please provide me with an example .
Thanks,
Viv
Hi walter,
That is awesome. Thanks a lot.
Can I also one more thing. Say if I have two object in the plots, say two polygon. The above method that you described deletes everything but what if I had to delete only one of them?
Sorry to be persistent.
Regards Viv
How do you want to distinguish which one you want to delete?
say one of them is of larger diameter and a different colour. Or the other method I was thinking was assigning each object a name which is then added to a list box in the gui. When I click on the appropriate name to be deleted, I press the delete button and the corresponding object in the plot gets deleted. I assume this is what you are asking.
It would be easier to do it "by name", by setting the Tag field of the patch() object to the name, and findobj(figurenumber, 'Tag', 'TagNameHere')
Awesome... Thanks Walters
Please "Accept" the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by