how to draw random numbers from the vector
17 views (last 30 days)
Show older comments
Nathalie on 19 Mar 2014
Hi, i have drawn a distribution based on on the generated vector of random numbers.
My question is:
- how to draw randomly 10 numbers, and , therefore, 10 values of that distribution.
- if it's impossible to find the values of this distribtution, how to simply draw 10 random numbers from , for example, vector of 1000 numbers.
Jos (10584) on 19 Mar 2014
If V is your vector of numbers, and N the number of values you want from it, there are various options:
V = 1:2:20, N = 5 % example data
R1 = V(ceil(numel(V)*rand(N,1)) % N random numbers with replacement
R2a = V(randperm(numel(V),N))) % N random values from V without replacement
R2b = randsample(V,N) % same, if you have the Statistics Toolbox
% and many more
More Answers (1)
José-Luis on 19 Mar 2014
x = rand(1000,1); %could be any other distribution, please see documentation
rand(10,1); %smaller sample from the same distrubution
your_vals = x(randperm(1000,10)); %ten numbers from the first sample
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!