【问题标题】:Compute the closest distance between an input matrix with two others using matlab使用matlab计算输入矩阵与其他两个矩阵之间的最近距离
【发布时间】: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,不是整数,而是标量,在本例中是实数。

标签: matrix matlab


【解决方案1】:

距离可以定义为norm of a difference

对于矩阵的距离,您可以根据您使用的matrix norm 定义多个距离。 Matlab的norm函数可以计算不同的范数,包括2-范数和Frobenius范数。

我建议你从 2 范数开始,看看这是否有助于你做你想做的事。

示例代码:矩阵xy 之间的距离:

dxy = norm(x - y, 2);

【讨论】:

  • 您通过norm 的第二个参数选择它们。见mathworks.com/help/matlab/ref/norm.html
  • 好吧,我假设是这样,但我将向量的 2 范数与矩阵的 2 范数混淆了。我更正了我的答案。矩阵的 2 范数实际上是由矩阵的投影产生的向量的最大 2 范数,或者是矩阵的最大奇异值。 Frobenius 范数是朴素的概括,只需将矩阵视为向量并计算 2-范数。
  • 正确,对于矩阵,我们有 1-范数、2-范数、Inf-范数和 Frobenius 范数。
  • :) 希望它能满足您的需求。
  • 如果使用向量 2-范数来定义向量(或点)距离,这与欧几里得距离相同。矩阵 2-范数是向量 2-范数到矩阵的推广,因此在这个意义上它类似于欧几里得。
猜你喜欢
  • 2022-11-21
  • 2018-03-23
  • 2018-12-02
  • 2011-09-21
  • 2021-05-07
  • 1970-01-01
  • 2018-08-05
  • 1970-01-01
相关资源
最近更新 更多