Change color of points if the coordinates are the same

3 views (last 30 days)
Hi, I'm new
I'm doing a simulation with Matlab and I like to change the color of a point when it have the same coordinate.
I have a matrix with all the 'x' and 'y' coordinates of all points and my program is plotting them one by one. I like to change the color when a point overlaps a other, so that I can see the density of points on this place.
Per example:
-All the plotted points are blue. (a lot)
-The coordinate of a single point is (1,1) => blue (this is ok)
- When a second plotted point have the same coordinate (1,1) it have to change in red
-When a third point passes throught the same coordinate (1,1) it have to change in yellow etc..
Do you have any ideas?
Thank you

Answers (2)

darova
darova on 30 Apr 2020
Look on this idea
  • create matrix
  • round data (snap to grid)
Fill matrix like
for i = 1:100
A(y(i),x(i)) = A(y(i),x(i)) + 1;
end
The matrix will show density
  4 Comments
Johnny
Johnny on 11 May 2020
nb_rotations = pi/2;
v_pl = 3;
v1 = 30;
v2 = v1;
R0 = 152;
R1 = 80;
R2 = 27.5;
R3 = 7.5;
d1=304/4;
d2=50;
d3=19;
theta1 = 0;%sup
dtheta1 = 1/200;
theta2 = 0;%ga
dtheta2 = 1/200;
theta3 = 0;%pel
dtheta3 = 1/200;
alpha=deg2rad(72);
angle = linspace(0,2*pi,200);
[line3x,line3y] = pol2cart(angle,R3);
plot(line0x,line0y);
while (theta1 < nb_rotations)
%%%%%%%%%%%% Calculations
x1 = d1*cos(theta1);
y1 = d1*sin(theta1);
x2 = x1+d2*cos(theta2);
y2 = y1+d2*sin(theta2);
x3 = line3x+x2+d3*cos(theta3);
y3 = line3y+y2+d3*sin(theta3);
%%%%%%%%%%%%%%% Loops
hold all
pause(0.001);
theta1 = theta1 + dtheta1*v_pl;
theta2 = theta2 + dtheta2*v1;
theta3 = theta3 + dtheta3*v2;
%%%%%%%%%%%%% Plots
plot(x3,y3,'b');
%%%%%%%%%%%%% Axes
axis([-160 160 -160 160]);
axis equal
grid on
end
Johnny
Johnny on 11 May 2020
This is the code. If one cercle overlay another, it have to change the color at this point

Sign in to comment.


darova
darova on 11 May 2020
Here are some recommendations:
Add these lines into your code
Add these lines at the end of your code
xx = xx(:); % make column
yy = yy(:);
xx = (xx-min(xx))/(max(xx)-min(xx))*98+1; % scale data between 1..99
yy = (yy-min(yy))/(max(yy)-min(yy))*98+1;
xx = round(xx); % round data
yy = round(yy);
A = zeros(100); % preallocation
for i = 1:length(xx)
A(yy(i),xx(i)) = A(yy(i),xx(i)) + 1; % fill matrix
end
imagesc(A)

Categories

Find more on Data Distribution 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!