If I have a vector of:
[4,5,6,7,11,12,13,14,21,22,23]
How can I, without a loop, extract the start/end values of all consecutive number blocks i.e. the desired result for the above vector would be a 2-column vector:
b =
4 7
11 14
21 23
Another approach:
x = [4,5,6,7,11,12,13,14,21,22,23];
x = x(:);
ind = find([1; diff(x)-1; 1]);
result = [x(ind(1:end-1)) x(ind(2:end)-1)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With