MATLAB: Extract group of identical values from an array

arrayextractindices

I have the array
a = [0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 1];
I want to extract the first and last index where a==1 as a group
o/p: [4 6; 12 15; 18 19];
Is there any efficient way to do this?

Best Answer

If you have the image-processing toolbox.