If I understood you want to find the minium distance between two points.
There are different between, if x1,y1,x2, and y2 are matrices/vectors then I suggest the following.
dist=sqrt((x2-x1).^2+(y2-y1).^2); %compute distance
[M,I] = min(dist); %find value of minimum distance and index
xf=x1(I); yf=y1(I); %this is the point on the first curve for the "intersection"
xs=x2(I); ys=y2(I); %this is the point on the second curve for the "intersection"
This should do what you want as it computes the distance and then looks for the minimum value. Now as said in the comments, let's also assume different x elements (different spacing) and/or different number of elements. (x1 and y1 must have the same elements otherwise you can't even plot it, and you'll need to "remesh" your grid/data points).
if length(x1)<length(x2)
l=length(x1);
c=length(x2);
xo=x1; xe=x2; yo=y1; ye=y2;
else
l=length(x2);
c=length(x1);
xo=x2; xe=x1; yo=y2; ye=y1;
end
dist=zeros(l,c);
for kk=1:l
xm=xo(kk)*ones(1,c); %you might have to change this depending on if your arrays are vertical/horizontal
ym=yo(kk)*ones(1,c); %same as xm but for y
dist(kk,:)=sqrt((xe-xm).^2+(ye-ym).^2); %compute distance
end
[M,I] = min(dist(:)); %find value of minimum distance and index
[row,col]=ind2sub(size(dist),I)
So what does this do, it runs a for loop the minimum amount of times, every iteration it checks 1 value of either against all the other values of the other line. This means it computes all the distances between all the points. Then you again find the minimum distance and you convert the position to a row and column number, the row tells you the index for the shortest array, and column tells you the index for the longest (you can add some stuff to automatically find which is which inside the if function or by adding a few lines at the end).
As mentioned by another user, this will be slow for large datasets 10000+ or 100000+ points(depends on your pc).