Approach No. 1
You can use setdiff at each iteration to exclude the current iteration id, for example:
for iteration_id = 1:3 indices = setdiff(1:3,iteration_id) end
Code Execution -
indices = 2 3 indices = 1 3 indices = 1 2
Approach No. 2 (vector image)
You can use a vectorized approach to generate all indices at once, which can be easily used inside the loop (s) if you need to use these indices -
num_iters = 3; %// Number of iterations all_indices = repmat([1:num_iters]',1,num_iters) %//' all_indices(1:num_iters+1:end)=[] valid_indices = reshape(all_indices,num_iters-1,[])'
Code Execution -
valid_indices = 2 3 1 3 1 2
source share