samer@4: function [Y,Z]=stochastic(X), samer@4: % stochastic - make rows sum to one (like probabilities) samer@4: % optionally returns the row sums as well samer@4: % samer@4: % stochastic :: [[N,M]] -> [[N,M]], [[N]]. samer@4: samer@4: Z=sum(X,2); samer@4: Y=X./repmat(max(Z,realmin),1,size(X,2)); samer@4: