It is entirely possible that there is a much easier way to go about this - but here is nevertheless a way. I've made a for loop that counts from the bottom up (this is important, as if you count from the top say i=1 2 3......26672, and when i=335 you delete row 335, then your old row 336 will be your new row 335, but i will hop on to 336 and thus "skip" the "real row 336", if you get what I mean :)
The loop starts from behind, counts 334 steps doing nothing, then sets delete to true, counts another 334 steps in which it deletes those indexes, then sets delete to false, counts 334 steps doing nothing, and so on so forth.
num=26672;
x = randn(num,1);
keep=334;
count=0;
spacing=1;
deleteactive=0;
for i=num:-1:1
count=count+spacing;
if count>keep-0.5
spacing=-1;
deleteactive=1;
elseif count<0.5
spacing=1;
deleteactive=0;
end
if deleteactive
x(i)=[];
end
end
Best Answer