The answer to question 1 is that bootsam
provides the indices of the resampled data. Specifically, the nth
column of bootsam
provides the indices of the nth
resampled dataset. In your case, to obtain the nth
resampled dataset you would use:
lead_resample_n = lead(bootsam(:, n));
depth_resample_n = depth(bootsam(:, n));
Regarding the second question, I'm guessing what you mean is, how would you just get a re-sampled dataset without worrying about applying a function to the resampled data. Personally, I would use randi
, but in this situation, it is irrelevant whether you use randi
or unidrnd
. An example follows that assumes 4 columns of some data matrix D
(as in your question):
%# Build an example dataset
T = 10;
D = randn(T, 4);
%# Obtain a set of random indices, ie indices of draws with replacement
Ind = randi(T, T, 1);
%# Obtain the resampled data
DResampled = D(Ind, :);
To create multiple re-sampled data, you can simply loop over the creation of random indices. Or you could do it in one step by creating a matrix of random indices and using that to index D
. With careful use of reshape
and permute
you can turn this into a T*4*M
array, where indexing m = 1, ..., M
along the third dimension yields the mth
resampled dataset. Example code follows:
%# Build an example dataset
T = 10;
M = 3;
D = randn(T, 4);
%# Obtain a set of random indices, ie indices of draws with replacement
Ind = randi(T, T, M);
%# Obtain the resampled data
DResampled = permute(reshape(D(Ind, :)', 4, T, []), [2 1 3]);