Find overlap from two scatter plots
Show older comments
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:
- 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 ?)
- 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.
Accepted Answer
More Answers (0)
Categories
Find more on Scatter Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!