Why the same code works for the matrix of size 5 but does not work for the matrix of size 100?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a sparse matrix L of zeros and ones and I want to change the non-zero entries to some fractions. This is my code:
beta = 0.5
n = size(L,1); %set n = dim(L)
rsv=ones(1,n)*L; %row sum vector of L
H =L;
for i=1:n
for j=1:n
if H(i,j) == 1
H(i,j)=1/((1-beta)*rsv(i)+ beta*rsv(j));
end
end
end
I found this code works for the matrix of size 5 but does not work for the matrix of size 100 (all entries stay unchanged).
Do you know why and how to change the code?
Many thanks,
Weijian
5 个评论
采纳的回答
Matt J
2013-5-12
If L has a single 1 on all columns then rsv(i)=1 for all i. If that happens then
1/((1-beta)*rsv(i)+ beta*rsv(j))
will equal 1 for all i and j.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!