Update:
So I found out it works if I calculate the b again in the event detection function and then implement condition .
function [value,isterminal,direction] = EventsFunc(t,y)
b = f1(t,y)
value = b+k;
isterminal = 1;
direction = -1;
end
I had another doubt arising out of this. Is the event detection done before next time step is processed by the ode45?
Also, can I pass other input arguments to EventsFunc, for example EventsFunc(t,y,param) ? Do I need to change the function definition in the options('Events',@EventsFunc) for that? Or any other way besides explicitly defining the parameters again inside the function.