MATLAB: Sequence/pattern problem

sequence pattern

Hi, I have a problem.
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ];
From above A, I want B like below :
B=[1 2 3 4 8 9 10 11 15 16 17 18 ];
Now, if my A is like below:
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
Then B will be like below:
B=[1 2 3 4 8 9 10 11 15 16 17 18 22 23 24];
Which means. first four elements of A will be in the B; then the next three elements of A will not be in B; then next 4 elements of A will be in B; and so on so forth..
Last few elements of A will be / will not be in the B depend on if they are in the sequence or not.
I tried to explain the case study above. Please let me know if something is not clear.
Thanks in advance.

Best Answer

A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ];
B1 = chop43(A(1:20))
B1 = 1×12
1 2 3 4 8 9 10 11 15 16 17 18
B2 = chop43(A)
B2 = 1×15
1 2 3 4 8 9 10 11 15 16 17 18 22 23 24
function B = chop43(A)
full_blocks = floor(length(A)/7);
blocksizes = repmat([4 3], 1, full_blocks);
leftover = length(A) - full_blocks*7;
if leftover > 0 & leftover <= 4
blocksizes(end+1) = leftover;
elseif leftover >= 5
blocksizes(end+1:end+2) = [4, leftover-4];
end
blocks = mat2cell(A, 1, blocksizes);
B = [blocks{1:2:end}];
end