oversampling an array randomly

16 次查看(过去 30 天)
I have an array that contains 300 observations, and i would like to oversample this array to 472 observation. but i would this to be done randomly (randomly pick 172 observations and duplicate them). I've been looking online but with no luck

采纳的回答

Chunru
Chunru 2021-9-1
a = randn(300, 1); % original data
idx = randperm(300, 172); % randomly pick 172 from 300
a1 = [a; a(idx)];
whos
Name Size Bytes Class Attributes a 300x1 2400 double a1 472x1 3776 double idx 1x172 1376 double
  2 个评论
Ahmed Abdulla
Ahmed Abdulla 2021-9-1
Thank you thats great, I have a follow up question. If I wanted to oversample more than double the number of observations for example oversample this 300 observation array to 771 observations for example is that possible
For my current question this is sooo perfect thank youuu
Chunru
Chunru 2021-9-1
If you want to ensure that original 300 are always included and addtional 471 are randomly sampled, you can do the following:
a = randn(300, 1); % original data
idx = randi([1 300], [471 1]); % 471 random numbers btw 1 and 300
a1 = [a; a(idx)];
whos
Name Size Bytes Class Attributes a 300x1 2400 double a1 771x1 6168 double idx 471x1 3768 double

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by