applying norm function to rows of matrix – Matlab

applying norm function to rows of matrix – Matlab

What about

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

or

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

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

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 doesnt support it natively.

applying norm function to rows of matrix – Matlab

if the first dimension is not too large:

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

Leave a Reply

Your email address will not be published.