I am working with gui. here i plot multiple line in a same graph.I want to add the function "When i select a point on the line in the graph.he can delete the selected line"

1 view (last 30 days)
Does it need?
items = get(h, 'Children');
delete(items(end));
thanks in advance...

Accepted Answer

Geoff Hayes
Geoff Hayes on 2 May 2015
Mehedi - see the attached GUI that can be used to demonstrate how you might delete a line from a graph given the position where you have clicked within the axes. Just run the app and press the Plot Data button to add some sine curves to the axes. The click near one of the curves and you should observe that it is removed/deleted from the axes.
The code is relatively simple - we keep track of the handles to all of the lines or curves that are drawn on the axes. We add a WindowButtonDownFcn event to the GUI so that it will respond to mouse button down (press) events. We assign a callback to this event and it will iterate through all of the handles and look for the one whose curve is closest to the pressed mouse button position. Once that curve has been found, it is then deleted.
Try running through the attached and see what happens!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!