查看单个帖子
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中控制点删除?

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

我怎么知道用户删除了哪些点? “删除”是指使用MATLAB工具(例如“画笔/选择工具”),然后单击“删除”按钮。



回答:

如果保存最初绘制的x和y数据,则可以在用户删除点以确定要删除的点之后将其与图中的其余'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,对于仍存在的点, 索引为零。如果用户仅删除了两个相邻点(如您所述,尽管您可能需要进行一些检查以确保确定),则可以轻松地用平均值替换这两个点,如下所示:

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);

更多&回答...
poster 当前离线   回复时引用此帖