Prev: ODE and external function as input
Next: axis units
From: Jos (10584) on 18 Mar 2010 09:01 "Christiaan " <chradem(a)hotmail.com> wrote in message <hnt1o9$2vl$1(a)fred.mathworks.com>... > I would like to create a vector [1x 200] which contains the values 1 and 0. The amount of ones is depending on a certain preset percentage and is randomly distrubuted over this vector. What is the best way to create such a vector? > > Take a look at the my quite simple engine NTRUE: http://www.mathworks.com/matlabcentral/fileexchange/10924-ntrue sizeM = [5 5] ; % size of matrix perc = 48 ; % percentage of true values (ones) % engine N = round(perc / 100 * prod(sizeM)) ; % number of true values M = ntrue(N, sizeM) % test sum(M(:)) ./ numel(M) Approaches using something like "random values smaller then threshold" are not bound ot give you an exact number of true (one) values ... hth Jos |