function c = cntabappend(c,a,b) % non-overflow % % c = cntabappend(c,a,b) % % Returns vector c plus 1 in the last element, up to the value of b. % When overflow in the last element, drop it down to the value of a. % When i=overflow in all elements, it appends the 1st element to the vector % c. Its value is a; % % Example: % c = 0; % for i=1:17 % c = cntabover(c,1,2) % end i = length(c); while i > 0 if c(i)+1 <= b c(i) = c(i)+1; break else c(i) = a; i=i-1; end end if i == 0 c = [1, c]; end % append new digit