Actually I found the solution:
I created a table with the x and y coordinates:
The small code is:
*********
table[x y];
[d,p] = min((table(:,1)-x_coord).^2 + (table(:,2)-y_coord).^2);
**************
and p gives the index in 'table' matrix that meets the condition of getting the minimum distance between the point (x_coord,y_coord) and both x and y vectors