フィルターのクリア

Saving multiple outputs from ODE45 with different dimensions?

1 回表示 (過去 30 日間)
Adham Alkhaja
Adham Alkhaja 2020 年 6 月 21 日
回答済み: J. Alex Lee 2020 年 6 月 21 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by