Create matrix with digital random numbers in matlab -
how can create in matlab matrix (20 x 12) random distribution of numbers 1 , 0, when in each column must have 40% of numbers 1 , 60% of numbers 0? must random distribution.
anyone me?
thanks ton!
an efficient method is:
- generate matrix of uniform random values between 0 , 1.
- for each column compute 40-percentile.
- for each column, set 1 entries lower or equal computed percentile, , set 0 remaining entries. assures desired fraction of values per column.
this can done prctile , bsxfun:
rows = 20; cols = 12; p = 40; %// percent of 1 values = rand(rows,cols); %// uniform random values between 0 , 1 perc = prctile(a,p); %// percentile of each column = bsxfun(@le, a, perc); %// 1 if lower or equal percentile, 0 otherwise
Comments
Post a Comment