data pick by given geometry

I have a set of scatter data, I want to do someting like below:
  1. use a given coordinate in the x-y system as input
  2. use this coordinate as center, draw a circle in this figure with given radius
  3. find the points inside this circle
is there anyway to do this in Matlab?
I attached a set of test data, below is the test code to reproduce a similiar figure like before:
load test
f=figure(1);
f.Units='pixels';
scatter(test(:,1),test(:,2));
f.Position(4)=f.Position(4)*0.5;
Thanks!
Yu

Respuestas (2)

Image Analyst
Image Analyst el 5 de Abr. de 2019

0 votos

Get the indexes with distances less than R then extract the corresponding x and y coordinates.
x = test(:,1);
y = test(:,2);
plot(x, y, 'b.', 'MarkerSize', 18)
uiwait(msgbox('Locate circle center'));
[xCenter, yCenter] = ginput(1)
distances = sqrt((x-xCenter).^2 + (y-yCenter).^2);
indexes = distances <= R;
xInside = x(indexes);
yInside = y(indexes);

4 comentarios

Yu Li
Yu Li el 5 de Abr. de 2019
Thanks for your reply, I have think about your approach, but...
in the figure, the x-y coordinate is not a 'axis-equal' format, which means that, the circle you see in the figure is indeed a ellipse.. not a circle. so I think the first approach should be to derive the ellipse function, and I'm working on it.
Image Analyst
Image Analyst el 8 de Abr. de 2019
How are you having your users interactively select points? As far as I know, there is no equivalent to the Image Processing Toolbox's roipoly() or imrect() or imfreehand() for non-image data (that is, plots).
Walter Roberson
Walter Roberson el 8 de Abr. de 2019
I am confused about which coordinate system the circle needs to be in ? Does the circle need to be in X Y (data) coordinates? Does the circle need to be in screen coordinates?
If you have the Image Processing Toolbox, you can use drawfreehand() to lassoo points. The function works on graphs also (in addition to images of course).
% Draw data
x = rand(100,1);
y = rand(length(x), 1);
scatter(x, y);
grid on;
% Let user lassoo some points interactively.
uiwait(msgbox('Draw a region'));
hFH = drawfreehand() % Required Image Processing Toolbox
% Get x and y points of what user drew.
xfh = hFH.Position(:, 1)
yfh = hFH.Position(:, 2)
% Find points inside the shape.
itsInside = false(length(x), 1);
for k = 1 : length(x)
itsInside(k) = inpolygon(x(k), y(k), xfh, yfh);
end
% Extract the points that are inside to new variables. (Optional)
xInside = x(itsInside);
yInside = y(itsInside);
% Plot a red asterisk over the points
% that are inside the region they drew.
hold on;
plot(xInside, yInside, 'r*');
0000 Screenshot.png

Iniciar sesión para comentar.

Preguntada:

el 4 de Abr. de 2019

Comentada:

el 8 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by