MATLAB: Choose two coordinates

coordinatenumber

hi there, i have a set of xy coordinates show in command window.So, I want to pick the coordinate where, there are the most many number repeated in y. here i attach the illustration for reference. see the attached for more information.
help me please.. thanks

Best Answer

idx = (y == mode(y));
x(idx)
y(idx)
or, if x and y are columns of a matrix
idx = (xy(:,2) == mode(xy(:,2)));
xy(idx,:)
EDIT TO ADD:
Note sure if I'm correctly interpreting your follow-up question, but try this (try a few times, because random numbers sometimes do strange things):
xy = randi(10,12,2); % Make some fake data
% Find the coordinates with the most equal y values
idx = (xy(:,2)==mode(xy(:,2)));
mostycoords = xy(idx,:);
% Take first and last coordinates
firstlast = mostycoords([1,end],:);
% Plot results
plot(xy(:,1),xy(:,2),'o',firstlast(:,1),firstlast(:,2))
axis([0,12,0,12])