Matlab - 求和& ^ 2

时间:2013-02-11 09:57:06

标签: matlab sum

this post,我得到了一个很好的答案,我只是想问一下,是什么:

maximum = (sum(sum(pdist2(x,y)))).^2;

在答案中意味着什么?

在我的问题中,并且,在那个位置,我计划从pdist2获得结果并总结结果。并且,在答案中,使用前面的格式。但是,当我使用它时,我会得到与我预期的不同的结果(总和),尽管代码的最终答案是正确的。

感谢。

1 个答案:

答案 0 :(得分:4)

以下是对(sum(sum(pdist2(x,y)))).^2

的逐步说明
pdist2(x,y) % your submatrix
sum(pdist2(x,y)) % The column sums of your submatrix
sum(sum(pdist2(x,y))) % The total sum of your submatrix
(sum(sum(pdist2(x,y)))).^2 % The element wise square of that sum

在这种情况下,这应该足够了,因为你正在对标量进行平方而不是矩阵或向量:

sum(sum(pdist2(x,y)))^2 % The square of that sum,