Yes, but rearrange the coding as follows:
tspan = [0:4:200];
y0 = [0.95 0.05 0];
[t,y] = ode45(@(t,y)odefcn(t,y),tspan,y0);
figure(1)
hold on
plot(t,y(:,1),'-o')
plot(t,y(:,2),'-*')
plot(t,y(:,3),'-d')
function dydt = odefcn(~,y)
if y(2)>0.3
A = 0.2;
else
A = 0.1;
end
B = 0.1;
dydt = zeros(3,1);
dydt(1) = -A*y(2)*y(1);
dydt(2) = A*y(2)*y(1)-B*y(2);
dydt(3) = B*y(2);
end
