Read about pdist2. You can use this to get whay you want.
P = rand(4,2) ; % random data for demo
iwant = pdist2(P) % the lower/ upper diagonal elements is what you wanted

Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!