How to undo a plot for multiple times?

2 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2015-8-13
编辑:Walter Roberson 2015-8-13
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by