I am trying to optimize this piece of code and get rid of the nested loop implemented. I am finding difficulties in applying a matrix to pdist function
For example, 1+j // -1+j // -1+j // -1-j are the initial points and i am trying to detect 0.5+0.7j to with point it belong by min distance approach .
any help is appreciated
function result = minDisDetector( newPoints, InitialPoints)
result = [];
for i=1:length(newPoints)
minDistance = Inf;
for j=1:length(InitialPoints)
X = [real(newPoints(i)) imag(newPoints(i));real(InitialPoints(j)) imag(InitialPoints(j))];
d = pdist(X,'euclidean');
if d < minDistance
minDistance = d;
index = j;
end
end
result = [result; InitialPoints(index)];
end
end