This question already has an answer here:
Q- Create a "counter" from 0:limit-1 (for example if you choose 3 it will display 0,1,2). The length of counter is not determined in the program and it should be determined when it is being run and the inputs can differ from each other
not really sure what you mean...but
for i = 0:limit-1
disp(i)
end
will display 0,1,2 ... limit-1
来源:https://stackoverflow.com/questions/16477924/have-to-create-a-matlab-counter