Euclidean norm of column difference
<p>I want to have the euclidean norm of the difference for every two columns in a matrix. So that for example <code>Column1-Column3</code> has its euclidean norm in the final matrix at <code>(1,3)</code> and <code>(3,1)</code>. I already have a code, but I would like to ask if there is a simpler and especially faster way to get this kind of a matrix.</p>

<pre><code>A = rand(4)
B=zeros(size(A));
for i = 2:size(A,1)
   diffCol = A - [A(:,i:end),A(:,1:i-1)];
   normsCol= sqrt(sum(diffCol.^2, 1));
   B=B+diag(normsCol(1:end-i+1),i-1);
end
B = B + B'
</code></pre>

<p>Example for a random 4x4 Matrix:</p>

<p><a href="https://i.stack.imgur.com/V3ErQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V3ErQ.png" alt="enter image description here"></a></p>