필터 지우기
필터 지우기

How to undo a plot for multiple times?

조회 수: 9 (최근 30일)
Ali Y.
Ali Y. 2015년 8월 13일
댓글: Ali Y. 2015년 8월 13일
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
  댓글 수: 1
Ali Y.
Ali Y. 2015년 8월 13일
Thank you very much, Wlater.

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

추가 답변 (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