【发布时间】:2013-12-12 05:08:25
【问题描述】:
如果我们考虑 3 个变量:x=1; y=2; z=3; 要知道 x 是否比 z 更接近 y,我们必须执行以下计算:
a=x-y; % -1
a=a.^2; % (-1).^2 = 1
b=x-z; %-2
b=b.^2; % (-2).^2 =4
%find the minimum
d=min(a,b); % 1
因此,我们注意到 x 比 z 更接近 y。
现在,让我们考虑 3 个矩阵 x、y 和 z,而不是变量。这是相同的概念,但我正在使用矩阵而不是变量。 回想一下,我想知道 x 是更接近 y 还是更接近 z。
顺便说一句,我尝试编写以下matlab代码:
clear all;
close all;
clc;
%I have 3 matrices x, y and z
x=[1 4 1 ; 4 5 3 ; 7 3 9]
y=[3 6 5 ; 6 5 7 ; 3 2 3]
z=[2 6 5 ; 3 7 6 ; 2 7 6]
%Compute the distance between x and y
a= x-y;
%squaring this distance
a_squared=a.^2;
%Compute the distance between x and z
b=x-z;
%squaring the distance
b_squared=b.^2;
%So to compute the closest distance among a_squared and b_squared, i think
%that i should compute the minimum.
d=min(a_squared,b_squared); % in this case, we get a new matrix which is the minimum. So how can i know if this d belongs to the cluster y or z ?
在这种情况下,我们得到一个新矩阵,它是最小值。那么我怎么知道这个 d 是属于集群 y 还是 z 呢?那么关于 d 的值,如何知道 d 属于 y 还是 z 呢?换句话说,我怎么知道 x 是更接近 y 还是更接近 z ?请我需要你的帮助和意见。任何帮助将不胜感激。
提前致谢。
【问题讨论】:
-
这个问答——math.stackexchange.com/questions/507742/…——你可能会感兴趣
-
您的问题相当于您考虑的矩阵之间的距离问题。例如,看看this post。一旦你选择了一个,你必须实现它,它就完成了:)。
-
感谢您的回答 :) ,因此在此链接中计算的距离将是整数值还是矩阵?如果它是一个整数值,那么这对我来说将是一个很好的答案和解决方案:)。请我需要你的回复:)
-
请你写一个答案给我至少两种距离方法的matlab代码。例如在这个有用的链接中写的 d1、d2..
-
@Christina,不是整数,而是标量,在本例中是实数。