MATLAB: Select a point on the graph

distancehypotenuseMATLABpythagorean

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
untitled.jpg
And I want to select the red point that is closest to the origin.
May someone help me with the code?

Best Answer

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