필터 지우기
필터 지우기

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 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