Pregunta

I have a Nx3 matrix (A) the columns are X,Y,Z respectively. I want to calculate the norm that is sqrt(X^2+Y^2+Z^2) for each row. I did a for loop for that:

for i = 1:length(A)
Result(i) = norm(A(i,:))
end

is there any other way to do it avoiding for loop?

Thanks

¿Fue útil?

Solución

You can do it like this:

sqrt(sum(A.^2, 2))

Your method returns a 1x3 where this returns a 3x1. So if you want you can transpose it but I doubt you really need to.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top