2010-12-17 136 views
2

我有一些图形。用户可以删除任何选定的点。如何控制MATLAB中的点删除?

我如何知道哪些点完全被用户删除? “删除”我的意思是使用MATLAB工具,如“画笔/选择工具”,然后单击删除按钮。

回答

3

如果保存最初绘制的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间隔,所以你的数据应该是一个单调递增的时间点向量,没有重复的值。因此,你可以找到通过执行以下操作中删除的点:

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

这给你一个logical index用药粥中删除的点和零点对于仍然存在的点。如果只有两个用户删除相邻点(如你所说,虽然你可能需要做一些检查,以确保),则可以按如下方便地更换这两个点与平均值:

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

我写的RR间隔Viewer程序,还有我想添加“平滑删除”,选择2个用户delets他们的选项,并在这中间线[A,B]出现一个像A1(x/2,y/2)这样的线的新点,但主要问题是获取删除点的线...... :( – AndrewShmig 2010-12-18 06:52:17

+0

@Andrew:我更新了我的答案展示你如何做到这一点。 – gnovice 2010-12-19 07:33:34

相关问题