How to control point deleting in 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 but开发者_如何学Cton.
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);
精彩评论