MATLAB: How to locate all ones in a binary array and change all adjacent elements to ones

arraysbinaryhelp

How do I locate all ones in a binary array and change all adjacent elements to ones?
For example, if I have [0 0 0 1 0 0 0 1 0 0],
how do I turn that into [0 0 1 1 1 0 1 1 1 0] ?
Thanks
[Edit] Ideally, I would like to be able to transform N # of elements on either side of every 1 to 1. For example, if N =3, then [0 0 0 0 0 1 0 0 0 0 0 0], would become [0 0 1 1 1 1 1 1 1 0 0 0].

Best Answer

One simple way, where V is your vector:
[0;V(1:end-1)] | V | [V(2:end);0]
or you could use conv.