I have generated a large dataset. Now I need to draw random samples from it. How can I do this?

2 ビュー (過去 30 日間)
For simulation, I have to draw 1000 random samples from a large dataset. I am looking for some efficient way of doing this. Can anyone help, please?

採用された回答

Harshit
Harshit 2012 年 11 月 15 日
For dataset w
p = randperm(length(w)); % Reshuffle their order randomly
z = w(p(1:N)); % Choose the first N of these
  2 件のコメント
Jos (10584)
Jos (10584) 2012 年 11 月 15 日
編集済み: Jos (10584) 2012 年 11 月 15 日
Note that the use of RANDPERM does not make it completely random because each original sample can only be drawn once ...
If you're after something like bootstrapping, use RANDI or RAND
Peter Perkins
Peter Perkins 2012 年 11 月 15 日
In recent versions of MATLAB, you can do what Harshit suggests in one line. When w is very long, this can make a difference:
z = w(randperm(length(w),N)); % select N randomly without replacement
As Jos suggests, use randi for random sampling with replacement. If you have access to the Statistics Toolbox, also see the datasample function, which allows sampling with or without replacement, and weighted or unweighted.

サインインしてコメントする。

その他の回答 (1 件)

Grzegorz Knor
Grzegorz Knor 2012 年 11 月 15 日
For example:
data = exp(-(-10:0.1:10).^2);
idx = randperm(numel(data));
N = 20;
idx = idx(1:N);
plot(idx,data(idx),'o')

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by