MATLAB求多点间的距离收益矩阵

用MATLAB求随机生成的m个二维坐标点各自到已知坐标点的m个坐标的距离,并生成距离矩阵

% 已知坐标点
knownPoints = [1, 2; 3, 4; 5, 6];

% 随机生成m个二维坐标点
m = 5;
randomPoints = rand(m, 2);

% 计算距离矩阵
distanceMatrix = pdist2(randomPoints, knownPoints);

% 打印距离矩阵
disp(distanceMatrix);