Select a point on the graph
7 views (last 30 days)
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?
Accepted Answer
Adam Danz
on 9 Oct 2019
Edited: Adam Danz
on 9 Oct 2019
To find the coordinate closest to the origin (0,0),
d = hypot(member_value(:,1),member_value(:,2));
[~, minIdx] = min(d);
plot(member_value(minIdx,1),member_value(minIdx,2),'ks','MarkerSize',12);
hypot() method avoids potential under/overflow: https://www.mathworks.com/help/matlab/ref/hypot.html
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.
0 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!