MATLAB: Find group of points in an array of points

grouping array value

I have a array x(i,j) where randomly x(i,j) = 1 or x(i,j) = 0. I need to find groups of x(i,j) adjacent to each other with x(i,j) = 1. Please help.

Best Answer

[L, num] = bwlabel(BW, n) solved the problem. Thank you!