I'm trying to generate a sparse stochastic matrix with Matlab but currently running into problems. Here is where I'm currently at.
N=10
i = round(rand(1,N)*10)+1
j = round(rand(1,N)*10)+1
S1 = sparse (i,j,1,N,N);
S = full(S1)
rowsum = sum(S,2);
S = bsxfun(@rdivide, S, rowsum);
Now this last line is where it fails. There are some zero rows in the sparse matrix.
So my question is how can I normalize each row yet preserve the zero rows?