MATLAB中如何控制点删除?

发布于 2024-10-08 15:21:44 字数 99 浏览 4 评论 0 原文

我有一些图形。用户可以删除任何选定的点。

我如何知道用户到底删除了哪些点? 我所说的“删除”是指使用 MATLAB 工具,例如“画笔/选择工具”,然后单击“删除”按钮。

I have some graphics. The user can delete any selected points.

How can I know which points exactly user deleted?
By "deleted" I mean using MATLAB tool such as "Brush/Select Tool" and then clicking Delete button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

荒芜了季节 2024-10-15 15:21:44

如果您保存最初绘制的 xy 数据,则可以将其与剩余的 'XData''YData' 在用户删除点后的图中确定删除了哪些点:

x = 1:10;           %# The initial x data
y = rand(1,10);     %# The initial y data
hLine = plot(x,y);  %# Plot the data, saving a handle to the plotted line
%# ...
%# The user deletes two points here
%# ...
xRemaining = get(hLine,'XData');  %# Get the x data remaining in the plot
yRemaining = get(hLine,'YData');  %# Get the y data remaining in the plot

您在评论中提到您正在绘制 RR 间隔,因此您的 x 数据应该是时间点的单调递增向量,没有重复值。因此,您可以通过执行以下操作找到已删除的点:

removedIndex = ~ismember(x,xRemaining);  %# Get a logical index of the points
                                         %#   removed from x

这将为您提供 逻辑索引,其中 1 表示已删除的点,0 表示仍然存在的点。如果用户仅删除了两个相邻点(正如您所描述的,尽管您可能需要进行一些检查以确保确定),您可以轻松地将这两个点替换为平均值,如下所示:

index = find(removedIndex);  %# Get the indices from the logical vector
xNew = [x(1:index(1)-1) mean(x(index)) x(index(2)+1:end)];  %# New x vector
yNew = [y(1:index(1)-1) mean(y(index)) y(index(2)+1:end)];  %# New y vector

然后您可以更新绘图因此:

set(hLine,'XData',xNew,'YData',yNew);

If you save the x and y data that is initially plotted, you can compare that with the remaining 'XData' or 'YData' in the plot after the user deletes points to determine which points were removed:

x = 1:10;           %# The initial x data
y = rand(1,10);     %# The initial y data
hLine = plot(x,y);  %# Plot the data, saving a handle to the plotted line
%# ...
%# The user deletes two points here
%# ...
xRemaining = get(hLine,'XData');  %# Get the x data remaining in the plot
yRemaining = get(hLine,'YData');  %# Get the y data remaining in the plot

You mentioned in a comment that you are plotting R-R intervals, so your x data should be a monotonically-increasing vector of time points with no repeated values. As such, you can find the points that were removed by doing the following:

removedIndex = ~ismember(x,xRemaining);  %# Get a logical index of the points
                                         %#   removed from x

This gives you a logical index with ones for points that were removed and zeroes for points that are still there. If there were only two neighboring points removed by the user (as you described, although you may want to do some checking to be sure), you can easily replace those two points with a mean value as follows:

index = find(removedIndex);  %# Get the indices from the logical vector
xNew = [x(1:index(1)-1) mean(x(index)) x(index(2)+1:end)];  %# New x vector
yNew = [y(1:index(1)-1) mean(y(index)) y(index(2)+1:end)];  %# New y vector

And then you can update the plot accordingly:

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