简体   繁体   中英

Normalize a matrix by rows containting zeros - MATLAB

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.

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,;));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM