clusteridx =
clustersegment (unos)
¶Calculate boundary indexes of clusters of 1’s.
The function calculates the initial index and end index of the sequences of 1’s in the rows of unos. The clusters are sought in the rows of the array unos.
The result is returned in a cell array of size 1-by-Np, where Np is the number of rows in unos. Each element of the cell has two rows. The first row is the initial index of a sequence of 1’s and the second row is the end index of that sequence.
If Np == 1 the output is a matrix with two rows.
The function works by finding the indexes of jumps between consecutive values in the rows of unos.
The following code
xhi = [0 0 1 1 1 0 0 1 0 0 0 1 1]; ranges = clustersegment (xhi) % The first sequence of 1's in xhi lies in the interval ranges(1,1):ranges(2,1)
Produces the following output
ranges = 3 8 12 5 8 13 ans = 3 4 5
The following code
xhi = rand(3,10)>0.4 ranges = clustersegment(xhi)
Produces the following output
xhi = 0 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 1 1 1 ranges = { [1,1] = 2 8 5 9 [1,2] = 1 6 10 3 7 10 [1,3] = 1 5 8 1 6 10 }
Package: signal