MATLAB: Find the gaps and add a few numbers

gaps

Hi
For a vector A, I am trying to find the gaps and count up/add 3 consecutive numbers from the lower number before continuing…
so for
A = [1 2 3 4 50 51 52 53 100 101 102];
At the end, I'd like to get
B = [1 2 3 4 5 6 7 50 51 52 53 54 55 56 100 101 102 103 104 105];
Ideas? Speed is always a virtue.
Thanks!
Willy

Best Answer

Sounds very very much like homework. Is it? Otherwise, what's the use case? In the meantime, here's a hint:
A = [1 2 3 4 50 51 52 53 100 101 102];
jumpIndexes = diff(A) ~= 1
See if you can figure out what to do. Or else just use a simple but intuitive for loop - it's actually really trivial and you should have no trouble with a for loop.