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:

  1. generate matrix of uniform random values between 0 , 1.
  2. for each column compute 40-percentile.
  3. 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

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -