문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top