Why animated plot (using for loop) from a (sol) struct is too slow ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 ?
0 commentaires
Réponses (1)
Steven Lord
le 7 Mai 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!