How not to delete one element of a figure when using cla?

조회 수: 8(최근 30일)
Leon 2020년 2월 8일
댓글: Leon 2020년 2월 8일
I have a map with coastlines and sampling stations that are added from other scripts using the command plot. When I move on to the next data set, I need to initialize the plot. What I want specifically is to keep the coastline plots (handle 'h' as below), but clear everything else (e.g., the sampling stations plotted on the map).
h = patch(app.mapPlot2, M2(:,1), M2(:,2), [0.62,0.83,0.50]);
My current program as above would delete everything including coastalines. Is there a way I can delete everything but the 'h' handle?
Many thanks!

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 8일
편집: Walter Roberson 2020년 2월 8일
No. cla always deletes the children of the axes.
You could put a copy of the object to keep into an axes in an invisible figure and copyobj() it instead of recreating it. However you mentioned mapping toolbox and one thing that cla does is reset back to a regular axes instead of a mapping axes and trying to copyobj a mapping child into a regular axes could easily be a problem. Like it would be easier to copyobj the entire axes.
  댓글 수: 5
Leon 2020년 2월 8일
Got you. Thanks!

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

추가 답변(1개)

Stijn Haenen
Stijn Haenen 2020년 2월 8일
Maybe you can delete one of the 'Children' of the figure.
and check if there is any data that can be deleted.
  댓글 수: 1
Leon 2020년 2월 8일
Thanks for pointing me to that direction.
To clarify, I do not want to delete anything about the h handle. I just want to delete the sampling station plots from other scripts with unknown handles.

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





Community Treasure Hunt

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

Start Hunting!

Translated by