How to count the amount of markers in a figure?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello guys,
For my thesis I am trying to create a figure/picture with a X amount of Stars/Dots/... as i needed this in my experiment. I found a code that is kind of able to do this, but the amount of Stars/Dots is not exactly equal to the amount that if fill in the code. Not sure how to make sure that the amount of stars/dots is exactly equal to the amount I fill in. Thanks in advance!
The code I am using:
x = rand(1, 10000);
y = rand(1, 10000);
minAllowableDistance = 0.05;
numberOfPoints = 50;
% Initialize first point.
keeperX = x(1);
keeperY = y(1);
% Try dropping down more points.
counter = 2;
for k = 2 : numberOfPoints
% Get a trial point.
thisX = x(k);
thisY = y(k);
% See how far is is away from existing keeper points.
distances = sqrt((thisX-keeperX).^2 + (thisY - keeperY).^2);
minDistance = min(distances);
if minDistance >= minAllowableDistance
keeperX(counter) = thisX;
keeperY(counter) = thisY;
counter = counter + 1;
end
end
plot(keeperX, keeperY, 'bx','MarkerSize',9);
axis([-0.1 1.1 -0.1 1.1]);
0 comentarios
Respuestas (1)
KSSV
el 5 de Mayo de 2021
x = rand(1, 10000);
y = rand(1, 10000);
minAllowableDistance = 0.05;
numberOfPoints = 50;
% Initialize first point.
keeperX = zeros([],1) ;
keeperY = zeros([],1) ;
keeperX(1) = x(1);
keeperY(1) = y(1);
% Try dropping down more points.
counter = 1;
for k = 2 : numberOfPoints
% Get a trial point.
thisX = x(k);
thisY = y(k);
% See how far is is away from existing keeper points.
distances = sqrt((thisX-keeperX).^2 + (thisY - keeperY).^2);
minDistance = min(distances);
if minDistance >= minAllowableDistance
counter = counter + 1;
keeperX(counter) = thisX;
keeperY(counter) = thisY;
end
end
plot(keeperX, keeperY, 'bx','MarkerSize',9);
axis([-0.1 1.1 -0.1 1.1]);
4 comentarios
Image Analyst
el 5 de Mayo de 2021
After your loop, you can count the number of non-zero keeperX values.
indexes = keeperX > 0;
% Extract only the ones we want to plot.
keeperX = keeperX(indexes);
keeperY = keeperY(indexes);
fprintf('Number of points plotted = %d.\n', length(keeperX));
plot(keeperX, keeperY, 'bx','MarkerSize',9);
Ver también
Categorías
Más información sobre General Applications en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!