MATLAB: How to skip the index of array

MATLABmatrix

i have the index array =[1,2,1,2,4]
the output matrix =[2,3,4,5,6]
the second output matrix=[1,3,4,5,6]
the third output matrix=[2,3,4,5,6]
and so on

Best Answer

Alternatively,
idx = [1,2,1,2,4];
N = 6; % max index
out = repmat(1:N, numel(idx), 1)';
out = reshape(out(out ~= idx), [], numel(idx))';
The rows in out are your outputs:
>> out
out =
2 3 4 5 6
1 3 4 5 6
2 3 4 5 6
1 3 4 5 6
1 2 3 5 6