MATLAB: How perform bootstrap balanced resampling of a dataset

bootstrap resampling

Basically, I'm trying to perform a bootstrap balanced resampling of a dataset K times, where data is an [N*1] vector of data samples, and the output should be an [N*K] matrix of bootstrap resampled data, where data d1 to dN each appear (randomly dispersed) exactly K times. I figured out how to do the resampling by using the unidrnd function, but I don't know how to make the data sets randomly appears K times. Please help.

Best Answer

I'm not sure...is this what you want?
N = 7; % Small values of N an d K to make it easier to see what it does.
K = 5;
data = rand(N,1);
kcopies = repmat(data,K,1);
shuffled = kcopies(randperm(numel(kcopies)));
output = reshape(shuffled,N,K)