Assuming the matrix is sorted by grouping numbers, as in the example, to get Boolean indices, you can do something like this: if your matrix a
I=a(1:end-1, 1) ~= a(2:end, 1)
It will store logical values by indexes corresponding to the last "grouping" numbers, except the last. Therefore, to get the lines you want, just do a(I, :) . And don't forget the last result. Or, as a single line:
[a( a(1:end-1, 1) ~= a(2:end, 1), : ); a(end, :)]
source share