Calculate Euclidean distance matrix in C
问题 I would like to convert this code which is written in MATLAB to C: matrix = [1 2 3; 4 5 6; 7 8 10] dis=zeros(9); for i=1:3 for j=1:3 dis(i,j)=sqrt(sum (abs((matrix(i,:)-matrix(j,:))))^2); end end The output is as follows: 0 9 19 9 0 10 19 10 0 Here is what I came up with in C: #include <stdio.h> #include <math.h> int main() { double distance[3][3] = {0}; double myArray[3][3] = { {1, 2, 3}, {4 , 5, 6}, {7, 8, 9} }; int i, j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { distance[i][j] =