MATLAB: Cutting a certain pattern from an array

arraycut array

Hello everyone!
I have a simple question regarding deleting certain pattern from array. For example I have a random array
A=[1 2 3 4 5 6 0 0 0 0 1 2 3 4 5 6 7 8 9 10 0 0 0 0 ...]
I want to delete all fragments, built of four zeroes. So cut away all B=[0 0 0 0] from a 1d array.
How can I implement it?

Best Answer

A = [1 2 3 4 5 6 0 0 0 0 1 2 3 4 5 6 7 8 9 10 0 0 0 0];
B = [0 0 0 0];
C = A(setxor(cell2mat(arrayfun(@(x)(x:x+length(B)-1),strfind(A,B), 'UniformOutput', false)), 1:length(A)));