How to write ||a-p||^2 in matlab code
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Soumili Sen
il 12 Mar 2021
Commentato: Soumili Sen
il 13 Mar 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 Commenti
Risposta accettata
Bjorn Gustavsson
il 12 Mar 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!