Creating a sparse matrix in Matlab with a specified number of independent Bernoulli +-1 nonzero entries -
How can we create matrix x, 1000 by 1000
in the matteback, which is sparse, say Are, 5% of independent Bernoulli + 1 nonzero entries?
I.e. In such a matrix, rho = = X <_0 / 10 ^ 6 = 0.05.
Choose 5% of irregular elements
n = Numel (x); Ind = Randie (n, round (.05 * n), 1);
Assign these elements with random variables
x (ind) = binorend (1, .5, length), 1) * 2-1;
Check for more information
To prevent duplicate rand
numbers, from the Statistics Toolbox, or randperm
as mentioned in some, or something like this
Ind = []; T = round (.05 * n); T1 = length (IND); While T1 & LT; T Ind (end + 1: t0) = rand (n, tt-1, 1); Ind = Unique (Ind); T1 = length (IND); End
Comments
Post a Comment