MATLAB: How to calculate euclidean distance between each row combination of matrix A and B and then find the minimums

kronecker sum

Let's say I have
A = [ 1 2; 1 1; 4 5]
B = [1 1; 1 2; 4 5]
I want
C = [ 1 ; 0; 18; 0; 1; 25; 25; 18; 0]
So
D = [1 ; 0; sqrt(18); 0; 1; 5; 5; sqrt(18); 0]
(e.g. first 3 numbers in D are the distance between row [1 2] and each row in B etc.)
Then I want to have E = reshape(D, 3, 3) So, answer = min(E) where I get the shortest distance from a row vector in A to all row vectors in B for each row vector in A. Can I compute this without using loops? Thanks!

Best Answer