2010-12-17 133 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

相關問題