function vec = next_ind_vec(vec, n) %vec is a vector consisting of distinct positive integers <= n, in %increasing order. %This function is for finding all subsets of 1:n, in lex order. l = length(vec); i = l; j = n; while(i > 0 && vec(i) == j) i = i - 1; j = j - 1; end if i == 0 vec = []; return end q = vec(i); vec(i:l) = q + (1:(l - i + 1));