Reputation: 103
I have a matrix which I want to normalize by rows (Euclidean space). I tried to use normr, which is great except for the fact that it normalizes (0,0) to (1/sqrt(2), 1/sqrt(2)). In that case I'd like it to be (0,0).
Any ideas? Thanks a lot.
Upvotes: 0
Views: 68
Reputation: 36720
Using any(M,2)
you get all rows which you want to normalize. Only run these rows through the function.
r=any(M,2);
M(r,:)=normr(M(r,;));
Upvotes: 5