How to undo a plot for multiple times?

2 views (last 30 days)
I want to delete a scatter plot's items for multiple times. My code is like
Function plot_callbacks (hObject, eventdata, handles)
figure (5)
scatter(x,y,'x')
hold on
scatitem = get(gca, 'Children');
handles.scatitem = scatitem;
guidata(hObject,handles)
Function undo_callbacks (hObject, eventdata, handles)
scatitem = handles.scatitem;
should_continue = true
while true
delete(scatitem(1))
scatitem(1) = []
should_continue = 0
end
In the second callback function, the line
delete(scatitem(1))
, just by it-self, deletes the last item, but just for one time. By the second function, I am trying to do the deletion for several times.
Does anyone know where did I write the code incorrectly? How can I make it working?

Accepted Answer

Walter Roberson
Walter Roberson on 13 Aug 2015
Edited: Walter Roberson on 13 Aug 2015
function undo_callbacks (hObject, eventdata, handles)
scatitem = handles.scatitem;
number_to_delete = 3; %for example
delete(scatitem(1:number_to_delete))
scatitem(1:number_to_delete) = [];
handles.scatitem = scatitem;
guidata(hObject, handles);
end
If you only want to undo one per call, change the 3 to 1.
The difference compared to your code is that my code updates handles.scatitem . You were trying to delete the same child every time

More Answers (0)

Community Treasure Hunt

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

Start Hunting!