![]() |
如何在MATLAB中控制点删除?
我有一些图形。用户可以删除任何选定的点。
我怎么知道用户删除了哪些点? “删除”是指使用MATLAB工具(例如“画笔/选择工具”),然后单击“删除”按钮。 [B]回答:[/B] 如果保存最初绘制的x和y数据,则可以在用户删除点以确定要删除的点之后将其与图中的其余[URL="http://www.mathworks.com/help/techdoc/ref/lineseriesproperties.html#XData"]'XData'[/URL]或[URL="http://www.mathworks.com/help/techdoc/ref/lineseriesproperties.html#YData"]'YData'[/URL]进行比较: 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 这为您提供了[URL="http://www.mathworks.com/help/techdoc/math/f1-85462.html#bq7egb6-1"]逻辑索引[/URL] ,对于已删除的点,该[URL="http://www.mathworks.com/help/techdoc/math/f1-85462.html#bq7egb6-1"]索引[/URL]为1,对于仍存在的点, [URL="http://www.mathworks.com/help/techdoc/math/f1-85462.html#bq7egb6-1"]索引[/URL]为零。如果用户仅删除了两个相邻点(如您所述,尽管您可能需要进行一些检查以确保确定),则可以轻松地用平均值替换这两个点,如下所示: 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); [url=https://stackoverflow.com/questions/4473577]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 14:17。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.