From the ode45 documentation:
[T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) solves as above while
also finding where functions of (t,y), called event functions, are
zero. For each event function, you specify whether the integration is
to terminate at a zero and whether the direction of the zero crossing
matters. Do this by setting the 'Events' property to a function, e.g.,
events or @events, and creating a function
[value,isterminal,direction] = events(t,y). For the ith event function
in events,
value(i) is the value of the function.
isterminal(i) = 1, if the integration is to terminate at a zero of this event >function and 0 otherwise.
direction(i) = 0 if all zeros are to be computed (the default), +1 if only the zeros where the event function increases, and -1 if only the zeros where the event function decreases.
Corresponding entries in TE, YE, and IE return, respectively, the time at which an
event occurs, the solution at the time of the event, and the index i
of the event function that vanishes.
The event function is set through the options argument, with the odeset function