📄 07-08.txt
字号:
% calculate the distance matrix of an array
function DM = distancem(A)
[amount,dim] = size(A);
plot(A(:,1),A(:,2),'.');
DM = zeros(amount);
for i=1:amount
for j=amount:-1:i+1
DM(i,j) = norm(A(i,:)-A(j,:));
DM(j,i) = DM(i,j);
end
end
if dim == 2
plot(A(:,1),A(:,2),'.');
hold on;
for i=1:amount
for j=amount:-1:i+1
plot([A(i,1),A(j,1)],[A(i,2),A(j,2)],'--');
dis_str = num2str(DM(i,j),3);
text((A(i,1)+A(j,1))/2,(A(i,2)+A(j,2))/2,dis_str);
end
end
end
hold off;
>> A=round(rand(4,2)*10);
>> D = distancem(A);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -