MATLAB: How to find non-zero values + lonely zeros in an array

cell arraysnon-zeros

Hey, I would like to find the non-zero cells plus the zeros that has no zeros before or after them. For example in the array [0 1 2 2 2 0 0 4 5 0 3 0 0 0 5] I'll get the indexes: 1,2,3,4,5,8,9,10,11,15.
Thanks!

Best Answer

v = [0 1 2 2 2 0 0 4 5 0 3 0 0 0 5];
union(strfind([false, v == 0, false], [0 1 0]), find(v))