Why animated plot (using for loop) from a (sol) struct is too slow ?

1 visualización (últimos 30 días)
Moustafa Aboubakr
Moustafa Aboubakr el 7 de Mayo de 2017
Respondida: Steven Lord el 7 de Mayo de 2017
I am solving the differential equations of a differential drive mobile robot using the ode23 solver and then plotting the results in an animated plot using a for loop. when i plot from
[t,s] = ode23(@Kpath, tspan, initials,[],p);
for j = 1:length(s(:,1))
q = plot(s(j,1),s(j,2),'ro','MarkerSize',5,'linewidth',1.5);
axis([-2.5 2.5 -2.5 2.5]);grid on;
pause(0.01)
delete(q)
end
the animation speed is normal however when i use the solution structure and then plot the results the animation is too slow ?
sol(i)= ode23(@mydglw4, tspan, initials,[],p);
initials = deval(sol(i),2);
t = linspace(0,2,100);
s = deval(sol(i),t);
is this related to the allocation of the struct ?

Respuestas (1)

Steven Lord
Steven Lord el 7 de Mayo de 2017
You're creating one line per point, then almost immediately deleting it. Instead, I would use odeset to specify odeplot as the OutputFcn. If you have to plot after finishing solving the ODE, instead consider using an animatedline instead of creating and deleting lines for each individual point.

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by