Filter löschen
Filter löschen

How to undo a plot for multiple times?

9 Ansichten (letzte 30 Tage)
Ali Y.
Ali Y. am 13 Aug. 2015
Kommentiert: Ali Y. am 13 Aug. 2015
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Aug. 2015
Bearbeitet: Walter Roberson am 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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by