Select a point on the graph
Show older comments
Hi given the following code,
figure(1);
scatter(x(:,1),x(:,2));
hold on;
scatter(member_value(:,1),member_value(:,2),'r');
legend({'Data','Pareto Frontier'})
I obtain a graph like this

And I want to select the red point that is closest to the origin.
May someone help me with the code?
2 Comments
Adam
on 9 Oct 2019
What do you mean by 'select' it? You can click on it and select it if you wish, but that depends what you want to do having 'selected' it.
If you mean programmatically find it then isn't it just a simple case of pythagoras, having subtracted your origin from all points? (Or some built-in distance function that does the maths for you anyway)
luca
on 9 Oct 2019
Accepted Answer
More Answers (1)
Turlough Hughes
on 9 Oct 2019
You can do the following:
[~,ind]=min(sqrt(member_value(:,1).^2+member_value(:,2).^2)); %find index for point closest to origin
hold on; plot(member_value(ind,1),member_value(ind,2),'.k');
Note, that if x was arranged as a row vector this will not work, but this is not the case for you.
Categories
Find more on Computational Geometry 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!
