Why animated plot (using for loop) from a (sol) struct is too slow ?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Steven Lord
2017-5-7
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!