Saving multiple outputs from ODE45 with different dimensions?

1 次查看(过去 30 天)
I have written an ODE45 function inside a for loop with an event where it stops at a zero-crossing. I have creating a variable that is three-dimensional and saves the output each iteration in the for-loop. The issue is that each iteration, the dimension of the output is different as each flags the stop condition at a different number of steps.
How can I save a changing variable size in one variable?
The code is,
counter_minus = 1;
for n=2:k
options=odeset('RelTol',1e-13,'AbsTol',1e-22,'Events',@(t,y) Xcrossing(t,y));
[t_out,xU_out]=ode113(@(t,y) DifferentialEquation(t,y),tspan,y0,options);
XU_OUTPUT(:,:,counter_minus) = xU_out;
counter_minus=counter_minus+1;
end

回答(1 个)

J. Alex Lee
J. Alex Lee 2020-6-21
I would use cells...also what's with the dual indexing? options can be defined outside since nothing is changing from iteration to iteration
% define outside the loop since nothing is changing
% AbsTol = 1e-22 < eps, is this realistic?
options=odeset('RelTol',1e-13,'AbsTol',1e-22,'Events',@(t,y) Xcrossing(t,y));
% pre-allocate
XU_OUTPUT = cell(k-1,1);
for counter = 1:(k-1)
% presumably something is changing with iterations...otherwise it's the same thing over and over again?
[t_out,xU_out]=ode113(@(t,y) DifferentialEquation(t,y),tspan,y0,options);
XU_OUTPUT{counter} = xU_out;
end

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by