Group cells in a matrix per column based on an indexed starting point
1 view (last 30 days)
I have two logical array matrices, A & B. I have the indexes of the 1s from A. I want to use these indexes as a starting point for grouping consecutive 1s in B, and then change everything else to 0.
The 1s in A represent the starting points of my events of interest, and B has the entire events as well as some false positives. I want to use the indexes from A to get rid of the false positives by changing them to 0 if they are not part of a series of 1s that begins with one of my indexes from A.
How would you do this?
TADA on 2 Jan 2020
you can map the ends of each series of ones using diff:
C = [diff(B, 1, 1) == -1; B(end, :)];
then check each occurence of C to see if it has a preceding index in A and no index in C between the two.
If the previous occurence of C is prior to the previous occurence of A it is a valid series
but if there is an occurence of C between the current C index and the previous occurence of A it means this is the end of a false positive chain, then you can zero out everything from the previous C index +1 up to the current C index