Assuming what you want is a vector, the example doesn't follow the description of the logic and the inputs given. Consider
According to b, a new sequence starts at index 23. So either c stops at 4 (at 22 elements long), or it continues for 6 more elements. If you chose to assert that c must be max(b) elements long, then it would terminate with 1. Etiher way, it would be inconsistent for it to stop at 5. If that's the way it must end, then that would have to be accomodated with a change to the logic.
c = [c a(1:max(b)-numel(c))]
I'm sure either case could be made more elegant once the details are clarified. For instance, in the aforementioned case where c is max(b) elements long and terminates with the first element of a new sequence: