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

1 visualización (últimos 30 días)
Soumili Sen
Soumili Sen el 12 de Mzo. de 2021
Comentada: Soumili Sen el 13 de Mzo. de 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 comentarios
KSSV
KSSV el 12 de Mzo. de 2021
Read about norm
Soumili Sen
Soumili Sen el 13 de Mzo. de 2021

Iniciar sesión para comentar.

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 12 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by