I have the following code to execute:$X$ = [0;0;0;0]; $sw$ = 0;for k = 1 : n    if (sw(k) == 0 && X(2,k)> 0.7 ) || (sw(k) == 1 && X(1,k) >0)        sw(k+1) = 1;        X(:,k+1) = X(:,k) +h*(A1*X(:,k) + B1*u);    else        sw(k+1) =0;        X(:,k+1) = X(:,k) +h*(A*X(:,k) + B*u);    endendThis is fine. I wanted to solve the same ODE using the bulit-in ode suite. How do I check for $sw$ and $X$ after each iteration to see which one of the two equations to solve.
Solving ODEs of Switched Systems using MATLAB ODE suite
matlab;ode