Here is some code I think will do what you want:
% some random data vector
data = rand(10,1);
N = numel(data);
% number of iterations you are performing
% (could be more or less than the number of data elements)
numIter = 25;
% compute sample indices without replacement
% (resampling will occur if numIter>N)
num = numIter;
idx = cell(ceil(numIter/N),1);
for i=1:numel(idx)
k = min(num,N);
num = num - k;
idx{i} = randperm(N, k);
end
idx = [idx{:}];
% main program loop
for i=1:numIter
val = data(idx(i));
% .. do something with sampled value
end
In the above example I get the following sample indices:
>> idx
idx =
Columns 1 through 14
3 8 2 6 1 5 10 7 4 9 4 8 5 7
Columns 15 through 25
1 10 6 9 3 2 1 4 10 5 3
>> tabulate(idx)
Value Count Percent
1 3 12.00%
2 2 8.00%
3 3 12.00%
4 3 12.00%
5 3 12.00%
6 2 8.00%
7 2 8.00%
8 2 8.00%
9 2 8.00%
10 3 12.00%
So for the first ten iterations, it was just a random permutation of the values. The same thing happens for the next ten iterations. Finally in the remaining five loop iterations, 5 random samples out of the ten were chosen.