我有一些图片。用户可以删除任何选定的点。
我如何才能知道用户到底删除了哪些点?我所说的“删除”是指使用MATLAB工具,比如“画笔/选择工具”,然后点击删除按钮。
发布于 2010-12-18 03:13:08
如果保存最初打印的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
您在注释中提到,您正在绘制R-R间隔,因此您的x
数据应该是一个单调递增的时间点向量,没有重复值。因此,您可以通过执行以下操作来查找已删除的点:
removedIndex = ~ismember(x,xRemaining); %# Get a logical index of the points
%# removed from x
这将为您提供一个logical index,其中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);
https://stackoverflow.com/questions/4473577
复制相似问题