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

2 Ansichten (letzte 30 Tage)
Soumili Sen
Soumili Sen am 12 Mär. 2021
Kommentiert: Soumili Sen am 13 Mär. 2021
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?
  2 Kommentare
KSSV
KSSV am 12 Mär. 2021
Read about norm
Soumili Sen
Soumili Sen am 13 Mär. 2021

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bjorn Gustavsson
Bjorn Gustavsson am 12 Mär. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by