Find overlap from two scatter plots

11 Ansichten (letzte 30 Tage)
Philipp Heinrich
Philipp Heinrich am 22 Mai 2019
Hey there,
I want to try to find the overlap of two scatterplots. My problem is that the scatterplot data is really huge.
Here is an example to understand the problem:
clearvars
close all
clc
%% Data
A.X = randi(1000,[89397,1]); % x Data for first scatter plot
A.Y = randi(1000,[89397,1]); % y Data for first scatter plot
B.X = randi(1000,[89397,1]); % x Data for second scatter plot
B.Y = randi(1000,[89397,1]); % y Data for second scatter plot
overlapX=zeros(89397,1); % x Data for overlapping points; is larger than probably necessary.
overlapY=zeros(89397,1); % y Data for overlapping points; is larger than probably necessary.
%%
k=1; %counter
for i=1:length(A.X)
for j=1:length(A.X)
if A.X(i) == B.X(j) && A.Y(i)==B.Y(j)
overlapX(k)=A.X(i);
overlapY(k)=A.Y(i);
k=k+1;
break;
end
end
disp(i)
end
This is what I made so far. The point is that the way I do it is highly inefficent.
Has somebody any suggestions on what to change ?
Current problems:
  1. I can not prevent matlab from checking every single element in B.X/B.Y. It would be helpfull to "flag" elements that already got a match so that matlab does not have to compare them. I assume that simply cutting them out of the array would be slow because matlab would have to resize the array every time (or is it faster in the end ?)
  2. I wonder if it increases the performance if I check beforehand if a pair of A.X(i) and A.Y(i) is already in overlapX and overlapY.
I hope that somebody got any ideas.

Akzeptierte Antwort

KSSV
KSSV am 22 Mai 2019
This problem can be solved with ease using knnsearch. Read about this function. YOu can get the nearest points in A for each point B using knnsearch. Along with the indices of n nearest points, you can get distance between the closest points. By having a look on distance and by setting up your desired criteria, you can study the overlapping.
  3 Kommentare
KSSV
KSSV am 22 Mai 2019
What you tried can be achieved with ismember and/or ismemebrtol.
Philipp Heinrich
Philipp Heinrich am 22 Mai 2019
Thank you so much for pointing this out !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by