MATLAB: Change the sequence of for loop index

for loopindexingMATLAB

I have a matrix x, with x = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …]'.
I now want a for loop or any vectorised form, so that I can store the elements c = [7 8 9 12 13 14 17 18 19…].
A for loop would then look something like:
for p = [7:1:9],[12:1:13]...
%do some calculations
end
x is quite a large vector (2400 entries) and I do not want to specify the terms in the square brackets for the entire matrix. Is there a way to change the index of the for loop, so that it can incremetnt between 1 and 3 as shown above?
Kind regards
Pascal

Best Answer

I solved the problem myself:
for k = 1:1:length(x)
for p = k*5+2:1:(1+j)*5-1
%do magic
end
end
Regards Pascal