My question is how can I create a variable "counter" where it starts at 1 and increases by 1 with each time-step until ode45 is done solving?
Make the current value of A to use (so, a) a shared variable. Also keep a record of the last time boundary that was successfuly passed.
Use an event function. The return value of the event function should be positive if the current input t is greater than the next time boundary after the last successful one. When you detect that the current input t is equal to the next time boundary (to within tolerance), update the shared a and update the record of last successful time boundary to be the current time, and return 0.
event functions are run only after a successful step, and they are run by a section of code that is devoted to finding the zero crossing. The assumption is that if the integration succeeded within tolerance to a location, that with the assumption of continuity, there should be a point between the old and the new where the event function returns 0 and which should also be within integration tolerance.
The assumption of course can fail if the function is discontinuous in one of the first two derivatives, since you might have stepped over a discontinuous area and thought you had succeeded in integration when you really had not succeeded.
So the above is how you can update a according to time.
Is it a good idea? No. But this answers the question you asked.