You are looking for elements where the convolution with the kernel [1,1,1] does not differ in the original. The only complication is that we must ignore the edge case:
x = [1 0 2 0 0 3 0 4 5 6 0 7 0 8]; y = conv(x,[1,1,1],'same'); ind = find(x==y); x(ind(2:end-1)) = 0
or
x(find(x(2:end-1)==conv(x,[1,1,1],'valid'))+1) = 0
Faced with the prospect of both positive and negative numbers, it is then based on Craigim's suggestions in the comments:
xx = abs(x); x(find(xx(2:end-1)==conv(xx,[1,1,1],'valid'))+1) = 0
source share