MATLAB: Ode events indexing error

ode45

I'm am trying to use an events function to stop my intergration when y(6) = c.vol_b.
Ph_1_init_conditions = [c.x0,c.y0,c.v0*cos(c.theta_i),c.v0*sin(c.theta_i),c.m_t,c.Vol_air];
ot1 = odeset('Event', @ph1term);
tspan1 = [0 0.5];
[t,r,te,ye,ie] = ode45(@drdt1, tspan1, Ph_1_init_conditions, ot1);
where @ph1term corrasponds the function below
function [value,isterminal,direction] = ph1term(y,c)
value = double(y(6) <= Vol_b)-1
direction = 1;
isterminal = 0;
end
%value = (y(6) - c.Vol_b);
I am getting an error saying:
Index exceeds the number of array elements (1).
Error in ph1term (line 2)
value = double(y(6) <= Vol_b)-1
Why is there indexing issue and what can i do to fix it.

Best Answer

The first parameter to the ode function and the event functions will always be the time, which will be a scalar.
Related Question