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

조회 수: 1 (최근 30일)
Moustafa Aboubakr
Moustafa Aboubakr 2017년 5월 7일
답변: Steven Lord 2017년 5월 7일
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 ?

답변 (1개)

Steven Lord
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.

카테고리

Help CenterFile 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!

Translated by