필터 지우기
필터 지우기

how to draw random numbers from the vector

조회 수: 9 (최근 30일)
Nathalie
Nathalie 2014년 3월 19일
답변: José-Luis 2014년 3월 19일
Hi, i have drawn a distribution based on on the generated vector of random numbers.
My question is:
  1. how to draw randomly 10 numbers, and , therefore, 10 values of that distribution.
  2. 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.
Thanks.

채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 19일
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

추가 답변 (1개)

José-Luis
José-Luis 2014년 3월 19일
doc ranperm
x = rand(1000,1); %could be any other distribution, please see documentation
1.
rand(10,1); %smaller sample from the same distrubution
2.
your_vals = x(randperm(1000,10)); %ten numbers from the first sample

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by