I have two matrices ((intx(i),inty(i),intz(i)) and Ceres(j)) with coordinates, and I need to find the two points closest to each other. From the MATLAB code I would expect to get the distance between the point in the first matrix, that is closest to a point on the second matrix, Ceres.
However, instead of getting this minimum value as a single number in disttemp I get an array of length(ceres_lim).
What am I doing wrong?
disttemp = 100000; % large number greater that the expected min distance
for i = 1:length(intz) % size of interpolated line point vector
for j = ceres_lim % array of indices close to line
distcur = pdist2([intx(i),inty(i),intz(i)],[Ceres(j,1),Ceres(j,2),Ceres(j,3)],'euclidean'); % distance between point on interpolated line (i) and scatter point on Ceres (j)
if distcur < disttemp
disttemp = distcur; % statement saves smallest value of distcur to disttemp to find min distance
end
end
end