I'm sure there should be an elegant solution for this (in MATLAB), but I just can't think about it right now.
I have a list with [classIndex, start, end], and I want to collapse consecutive indexes of the class into one group as follows:
it
1 1 40
2 46 53
2 55 55
2 57 64
2 67 67
3 68 91
1 94 107
Gotta turn into this
1 1 40
2 46 67
3 68 91
1 94 107
How to do it?
EDIT
Nothing, I think I got it - it's almost like fmarc solution , but it gets indexes correctly
a=[ 1 1 40
2 46 53
2 55 55
2 57 64
2 67 67
3 68 91
1 94 107];
d = diff(a(:,1));
startIdx = logical([1;d]);
endIdx = logical([d;1]);
b = [a(startIdx,1),a(startIdx,2),a(endIdx,3)];
Jonas source
share