从 MATLAB 图中删除点和线
我有一个用户可以点击进入的图形。单击的坐标将存储在两个向量 x 和 y 中。然后我通过plot(x_new, y_new)绘制新创建的点,并且还为该点创建了一个上下文me nu,其中有一个标签删除点
。当点击对此,我只需删除 x 和 y 向量的相应值即可。
现在我需要以某种方式删除绘制的点。目前我正在这样做:删除点时,我只需清除当前轴cla
并立即重新绘制所有点。但不知何故,我觉得这不是最好的方法,因为我还想显示文本和用户输入点之间的一些连接线,并且当每次都需要重新绘制所有内容时,它可能会变得非常慢......
所以我想知道最好的方法是什么? 简单地存储每个点返回的绘图句柄并在删除点时删除这些对象会好吗?连接线和文本也一样吗?
谢谢!
I have a figure where the user can click into. The coordinates of the click will get stored in two vectors x and y. Than I plot the newly created point via plot(x_new, y_new)
and further there's a context me nu being created for this point which has a label delete point
.When clicking on it, I simply remove the corresponding values of the x
and y
vectors.
Now I need to somehow delete the plotted point. Currently I'm doing it this way: When deleting points, I simply clear the current axes cla
and redraw all points at once. But somehow I feel this isn't the best method since I want to also display text and some connection lines between the points on user input and it could get pretty slow when all the stuff needs to be redrawn everytime...
So I'm wondering whats the best way to do it?
Would it be good to simply store the returning plot-handles for each point and than delete those objects when deleting the point? Same for connection lines and texts?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
XData
和YData
属性直接操作一行的基础数据。要删除索引
idx
处的点:You can manipulate the underlying data of a line directly using the
XData
andYData
properties.To remove the point at index
idx
:还有另一种选择,使用“refreshdata”,但我不喜欢它,因为它慢得多并且会创建丑陋的代码。
所以我对@Nzbuu解决方案投票+1,但如果有人感兴趣的话我会添加这个
There is also another option, using "refreshdata", but I don't like it, because it is much slower and creates ugly code.
So I vote +1 to @Nzbuu solution, but I add this if it interests someone