MATLAB: Find easy patterns in a logic vector

Image Processing Toolboxpattern recognition

Hello everyone,
I am a little bit confused performing an easy procedure.
I have a long logic vector, for example:
R = [1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 1 1 1 0 0 1 0 0 1]
It would be nice to localize this information in smalls groups.
For instance, in this position u have a group of three, here a group of 5, here only one.
Is there any specific command to do that?
Thanks!

Best Answer

It doesn't handle the edges perfectly, but you might want to start with
diff(find(diff(R)))
The diff( R ) is a logic vector indicating if the ith element is end of a group. The find() gets the indices on which group end. The outer diff() then determines how many elements are between group endings.