MATLAB: How to select every nth number of trials and put them in a separate column

binningsample with replacement

I have 180×4 matrix that is sorted by two columns. There are 5 levels or variable A and 6 levels of variable B (30 groups total). Variables C and D are just responses. I would like to sample from each group with replacement. E.g. This would mean that if had a loop with 30 iterations, I would select a sample from each of the 30 groups. If I had 60 iterations, I would select 2 samples from each group.

Best Answer

For a vector
X = rand(100,1) ;
X10 = X(1:10:end) ; % pick every 10'th value
X7 = X(1:7:end) ; % pick every 7'th value
For a matrix
X = rand(180,4) ;
X10 = X(1:10:end,:) ; % pick every 10'th row
X9 = X(1:9:10,:) ; % pick every 9th row