MATLAB: Pick values around an index

indexindexingvalue groups

Hello !
I have an problem to which I'd like to find an efficient solution.
Let the vector :
[0, x, x, x, x, 0, x, x, x, 0, x, x, x, x, x]
where x is an unkown integer.
I'd like to extract the first 3 x's starting from each '0'
So I thought about indexing the '0's which gives me something like :
[1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0]
And then use this index to extract groups of value around the '1's
or generate from the previous index another one taking into account the first three 'x's :
[1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0]
But it seems that there is no easy way to do that.
Is there an indexing syntax or a function that would allow me to do that ?
Thank you for your time ~

Best Answer

>> V = [0, 11, 12, 13, 14, 0, 21, 22, 23, 0, 31, 32, 33, 34, 35];
>> X = logical(conv([1,1,1,1],+(V==0)));
>> Z = V(X(1:numel(V)))
Z =
0 11 12 13 0 21 22 23 0 31 32 33