Change time of a matlab simulation
이전 댓글 표시
I have a trajectory simulation with a time setup as follows:
T = 100; % Simulation time
dt = 1;
N = T/dt + 1;
for ii = 2:N
....
plot(x1,y1,'b--')
hold on
plot(x1(ii1),y1(ii1),'r*')
hold off
xlim([-10,10]/2+3)
ylim([-10,10]/2)
xlabel(num2str(ii1*dt))
pause(dt*0.1)
end
I would like the simulation to run faster, for say T = 5-10, but when I do that I only see the first 5-10 "seconds" of the simulation. Do I need to change the pause and/or the dt?
답변 (1개)
Mischa Kim
2014년 5월 3일
편집: Mischa Kim
2014년 5월 3일
Kelilah, you could use something like:
dt = 1;
T = 100;
t = 0:dt:T;
x1 = 1:100;
y1 = sin(x1);
plot(x1,y1,'b--')
for ii = 2:numel(t)
hold on
plot(x1(ii),y1(ii),'r*')
hold off
xlim([0 100])
ylim([-2 2])
xlabel(num2str(ii*dt))
pause(dt*0.1*(2 - 1.5*(t(ii)>=20 && t(ii)<=40)))
end
I adapted your code/requirements to better show what is happening. The above simulation runs faster between t = 20 and t = 40 by simply reducing the pause time in that simulation range. Of course, you need to make sure that your data (x1,y1) correspond to the time vector t.
카테고리
도움말 센터 및 File Exchange에서 Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!