Try use logical indexing. I am not familiar with ODE45 so there might be a nicer way to do this but in terms of plotting you could try this.
The plot I get is only a quadrant tho so you might need to play with the code a bit. I did not fully understand your question so I hope that helps a bit.
Lind = (y(:,2) < 0 & t < pi);%use logical indexing