applying norm function to rows of matrix - Matlab


This question already has an answer here:


What about

 norms = sqrt(sum(A.^2,1))


 norms = sqrt(sum(A.^2,2))?

depending on whether your coordinates are in rows or in columns.

if the first dimension is not too large:

norms = sqrt(diag(A * A'));

If readability is a bigger consideration than performance you might also consider:

norms = cellfun(@norm,num2cell(A,2));

This pattern is also adaptable to other operations along one dimension you might want to perform where MATLAB doesn't support it natively.

Need Your Help

Why use/develop Guice, when You have Spring and Dagger?

java spring guice dagger-2

To my knowledge, Dagger does generate code, while Guice and Spring rely on runtime processing, thus Dagger works faster, but requires more work on programmer side. Because of performance edge it's ...