Random sampling more elements than data contains

2 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2017 年 8 月 16 日
コメント済み: MiauMiau 2017 年 8 月 16 日
Hi, I am familiar with the datasample function, however, datasample does not allow for sampling more from a vector x than the number of elements x contains. I want to however do exactly this, i.e. bootstrapping in some way (however it seems that the bootstrapping function in Matlab requires specifying a function which is then applied to the data, something which I don't want). For instance, if x contains 10 elements, I might want to sample (with replacement) a new vector which would have 20 elements. What function can I use? Thanks

採用された回答

Image Analyst
Image Analyst 2017 年 8 月 16 日
Use randi():
x = rand(1, 10); % Create sample data for this demo.
indexes = randi(length(x), 1, 20)
sampled_x = x(indexes)
Of course, some elements may not get chosen at all while others may get chosen once, or 2,3,4, etc. times but you said you were okay with that since you said "with replacement".
  1 件のコメント
MiauMiau
MiauMiau 2017 年 8 月 16 日
yes that is exactly ok. many thanks!!!

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by