简体   繁体   中英

Matlab - summation & .^2

In this post , where I received a nice answer, I just want to ask, what does:

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

mean in the answer?

In my question, and, on that location, I was planning to get the result obtained from pdist2 and sum up the result. And, in the answer, the preceding format is used. But, when I use it I get a different result (for sum) as I expected, although that the final answer of the code is correct.

Thanks.

Here is a step by step explanation of (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

This should be sufficient in this case as you are squaring a scalar and not a matrix or a vector:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM