How to write ||a-p||^2 in matlab code

1 次查看(过去 30 天)
Hello all,
I have two variables 'a' and 'p Now I want to express this expression as
f=||a-p||^2;
What will be the matlab code for this expression?

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2021-3-12
Have a look at the norm function and its help and documentation. If your a and p are  [n x m] arrays and you want to get ||a-p||^2 for each row you might do something like this:
n_ap = sum((a-p).^2,2);
adapt to handle complex values if necessary.
HTH

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by