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

2 次查看(过去 30 天)
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).
cla(app.mapPlot2);
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 个评论
Walter Roberson
Walter Roberson 2020-2-8
If you set the Position of the second axes to be the same as the Position of the first axes, then the second one will be on top of the first provided it was drawn later. You can use uistack() to force a particular relative position to be certain.

请先登录,再进行评论。

更多回答(1 个)

Stijn Haenen
Stijn Haenen 2020-2-8
Maybe you can delete one of the 'Children' of the figure.
type:
h.Children
and check if there is any data that can be deleted.
or
h.Children.Children
  1 个评论
Leon
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.
Thanks.

请先登录,再进行评论。

类别

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

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by