Find the distance from one point in a matrix to all other points in a matrix
I have a matrix a and I want to calculate the distance from one point to all other points . So really the outcome matrix should have a zero (at the point I have chosen) and should appear as some sort of circle of numbers around that specific point. This is what I have already but I cant seem to get the correct outcome. a = [1 2 3 4 5 6 7 8 9 10] for i = 2:20 a(i,:) = a(i-1,:) + 1; end N = 10 for I = 1:N for J = 1:N dx = a(I,1)-a(J,1); dy = a(I,2)-a(J,2); distance(I,J) = sqrt(dx^2 + dy^2) end end chappjc Your a matrix is a 1D vector and is incompatible with the nested loop, which computes