Change time of a matlab simulation
Show older comments
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?
Answers (1)
Mischa Kim
on 3 May 2014
Edited: Mischa Kim
on 3 May 2014
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.
Categories
Find more on Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!