Having difficulty understanding the following code in Matlab to calculate Euclidean distance between two points, where X is the data to be classified and label corresponds to cluster membership.
label = ones(1, data_dim);
[N,~]=size(X);
[c,~]=size(clusters);
dist = zeros(N,c);
for i = 1:c
dist(:,i) = sum(bsxfun(@minus, X, clusters(i,:)).^2, 2);
end
[~,label] = min(dist,[],2);
Can anyone explain what is going on here and maybe explain it from first principles without using bsxfun
?