[英]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)).
我尝试使用normr,除了将(0,0)标准化为(1 / sqrt(2),1 / sqrt(2))之外,这非常有用。 In that case I'd like it to be (0,0).
在那种情况下,我希望它是(0,0)。
Any ideas? 有任何想法吗? Thanks a lot.
非常感谢。
Using any(M,2)
you get all rows which you want to normalize. 使用
any(M,2)
您可以获得要标准化的所有行。 Only run these rows through the function. 仅通过函数运行这些行。
r=any(M,2);
M(r,:)=normr(M(r,;));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.