For loop data extraction

3 visualizaciones (últimos 30 días)
Zachary Braida
Zachary Braida el 12 de Nov. de 2020
Comentada: Zachary Braida el 12 de Nov. de 2020
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

Respuestas (1)

Jon
Jon el 12 de Nov. de 2020
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 comentarios
James Tursa
James Tursa el 12 de Nov. de 2020
Editada: James Tursa el 12 de Nov. de 2020
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 el 12 de Nov. de 2020
Thank you! That second one works. If you add it as an answer outside the comment, I will accept it as the working!

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by