从 MATLAB 图中删除点和线

发布于 2024-12-22 05:52:38 字数 377 浏览 5 评论 0原文

我有一个用户可以点击进入的图形。单击的坐标将存储在两个向量 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人如玉 2024-12-29 05:52:38

您可以使用 XDataYData 属性直接操作一行的基础数据。

要删除索引 idx 处的点:

XData = get(h_line, 'XData');
YData = get(h_line, 'YData');
XData(idx) = [];
YData(idx) = [];
set(h_line, 'XData', XData, 'YData', YData);

You can manipulate the underlying data of a line directly using the XData and YData properties.

To remove the point at index idx:

XData = get(h_line, 'XData');
YData = get(h_line, 'YData');
XData(idx) = [];
YData(idx) = [];
set(h_line, 'XData', XData, 'YData', YData);
最偏执的依靠 2024-12-29 05:52:38

还有另一种选择,使用“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文