Magnitude of a matrix
48 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
David Harra
le 16 Sep 2021
Commenté : Star Strider
le 16 Sep 2021
I have a 1000 x 3 matrix where each column is associated the the x,y and z-direction. For each row I want to find the magnitude such that I have a 1000 x 1 array returned.
x=randi(100,1000,3);
X=norm(x(1:1000,1:3))
I tried this but I am only only getting a single number rather than a 1000 x 3 array.
Thanks
Dave :)
0 commentaires
Réponse acceptée
Star Strider
le 16 Sep 2021
x=randi(100,1000,3);
X=vecnorm(x,2,2)
.
2 commentaires
Star Strider
le 16 Sep 2021
My pleasure!
The first 2 specifies the 2-norm (rather than others), and the second 2 specifies that the function is to take the norm across the rows (dimension 2) rather than down the columns (dimension 1, the default dimension) or other dimensions if the matrix had more than 2.
Specifying only the matrix would take the 2-norm of the columns.
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!