OK, this is a hugely simplified example on a much much smaller and simpler system, and this is not the same ODE at all, but the question is generic. My code is too big to post usefully. What I have as a test is given below.
If I set tspan such that it's just the end points, it gives me y(1) and y(2) and yout at every successfully calculated time step within the interval tspan; if I put any intermediate points into tspan, it gives me y(1), y(2), and yout at only those points. What I want is y(1) and y(2) at the ends only, and yout at all intermediately calculated points.
function [t,y, yout]=opctest
tspan = [0, 10*pi]; y0=[0,1]; opts=odeset('OutputFcn',@opc); county = 0; [t,y] = ode45(@myfun,tspan,y0,opts);
function f = myfun(t,y)
f(1,1) = cos(t) + y(2);
f(2,1) = sin(t) - y(1);
function status = opc(t,y,flag)
yout(county+1) = y0(1);
status = 0;
ny = size(y,2);
yout(county+1:county+ny) = y(1, 1:ny);
county = county+ny;