I am having trouble finding a way to extract data at then end of a for loop with function.
for i = 1:length(height)
% solve coupled drag ODE
options = odeset('RelTol',1e-5,'AbsTol',1e-7); % ODE options
f = @(t,x) horizEqns(Isp,Wo,Wb,Wdot,msl,1,height(i),t,x); % the equations that will be solved
[t,soln] = ode45(f,[0 maxtime],[0. v0],options);
end

답변 (1개)

Jon
Jon 2020년 11월 12일

1 개 추천

You overwrite your t and soln values with each loop iteration. If you want to save those to use them later you need to put them into arrays. Assuming t and soln have the same length each time
[t(:,i),soln(:,i)] = ode45(f,[0 maxtime],[0. v0],options);

댓글 수: 3

Zachary Braida
Zachary Braida 2020년 11월 12일
I initially tried that but get this as the error:
Unable to perform assignment because the indices on the left side are not compatible
with the size of the right side.
James Tursa
James Tursa 2020년 11월 12일
편집: James Tursa 2020년 11월 12일
Probably because soln has more than one column.
Try this
[t,soln(:,:,i)] = ode45(f,[0 maxtime],[0. v0],options);
or this
[t,soln{i}] = ode45(f,[0 maxtime],[0. v0],options);
Zachary Braida
Zachary Braida 2020년 11월 12일
Thank you! That second one works. If you add it as an answer outside the comment, I will accept it as the working!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 11월 12일

댓글:

2020년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by