How to detect isolated points in a vector
2 次查看（过去 30 天）
I have a vector (see attachment), and I would like to detect isolated points (marked with red cicles in the image). Isolated in that sense, that same values have a certain distance to these. I would need the indices.
I believe this code does what you ask for:
N = 500;
isolated = false(size(iidx));
L = length(iidx);
for k = 1:L
left = max(1,k-N):k-1;
right = k+1:min(L,k+N);
isolated(k) = ~any(iidx([left, right]) == iidx(k));
result = find(isolated);
plot(result, iidx(isolated), "ro")
I don't see an obvious way to avoid the loop. If there are concerns about performance, I can think about it a bit more - or perhaps, others have an idea.
Note that it does not identify two of the points that you have circled. If you zoom in, you will see that there are two consecutive identical values there. My understanding is that you did not want to extract these, even though they look isolated on the first glance? If you wanted these, I do not fully understand the question yet.