首页 \ 问答 \ 用mahalanobis度量的matlab Pdist2(matlab Pdist2 with mahalanobis metric)

用mahalanobis度量的matlab Pdist2(matlab Pdist2 with mahalanobis metric)

我如何使用'mahalanobis'指标使用pdist2? 我写这个代码:

u=[1 2 3; 4 5 6; 7 8 9];
n=[1 2 5;2 5 7;5 7 9];
covu=nancov(u);

Z=pdist2(u,u,'mahalanobis',covu);

但我得到这个错误:

??? Error using ==> pdist2 at 298
The covariance matrix for the Mahalanobis metric must be symmetric and positive definite.

Error in ==> Untitled at 5
Z=pdist2(u,u,'mahalanobis',covu); 

尽管变量'covuu'是对称矩阵并且也是正的。 这是covu:covu =

 9     9     9
 9     9     9
 9     9     9

我怎样才能用“mahalabobis”度量来计算pdist2?


How can i use pdist2 with 'mahalanobis' metric? I write this code :

u=[1 2 3; 4 5 6; 7 8 9];
n=[1 2 5;2 5 7;5 7 9];
covu=nancov(u);

Z=pdist2(u,u,'mahalanobis',covu);

But i get this error:

??? Error using ==> pdist2 at 298
The covariance matrix for the Mahalanobis metric must be symmetric and positive definite.

Error in ==> Untitled at 5
Z=pdist2(u,u,'mahalanobis',covu); 

although variable 'covuu' is symmetric matrix and also positive. this is covu: covu =

 9     9     9
 9     9     9
 9     9     9

How can i calculate pdist2 with "mahalabobis" metric?


原文:https://stackoverflow.com/questions/48443529
更新时间:2024-02-27 06:02

最满意答案

约定是,如果你不指定视图名称,相应的视图将是该操作的名称。 所以:

public ActionResult MethodA()
{
    return View();
}

将呈现~/Views/ControllerName/MethodA.cshtml

但是你也可以指定一个视图名称:

public ActionResult MethodA()
{
    return View("FooBar");
}

现在将呈现~/Views/ControllerName/FooBar.cshtml视图。

或者,您甚至可以指定不在当前控制器的视图文件夹内的完全限定的视图名称:

public ActionResult MethodA()
{
    return View("~/Views/Foo/Baz.cshtml");
}

显然,所有这些都假定Razor作为视图引擎。 如果您使用的是WebForms,请使用.aspx.ascx替换.cshtml (如果您使用的是partials)。

例如,如果没有视图,它甚至会告诉你在什么位置以什么顺序查找视图:

在这里输入图像描述

记住:ASP.NET MVC完全是关于约定而不是配置。


The convention is that if you don't specify a view name, the corresponding view will be the name of the action. So:

public ActionResult MethodA()
{
    return View();
}

will render ~/Views/ControllerName/MethodA.cshtml.

But you could also specify a view name:

public ActionResult MethodA()
{
    return View("FooBar");
}

and now the ~/Views/ControllerName/FooBar.cshtml view will be rendered.

Or you could even specify a fully qualified view name which is not inside the views folder of the current controller:

public ActionResult MethodA()
{
    return View("~/Views/Foo/Baz.cshtml");
}

Now obviously all this assumes Razor as view engine. If you are using WebForms, replace .cshtml with .aspx or .ascx (if you are working with partials).

For example if there is no view it will even tell you where and in what order is looking for views:

enter image description here

Remember: ASP.NET MVC is all about convention over configuration.

相关问答

更多