pause button not working
6 views (last 30 days)
Show older comments
Kristian Dolghier
on 16 Apr 2020
Answered: Geoff Hayes
on 21 Apr 2020
hey all
ive been trying to use the pause function in MTLAB to achieve a cool animation effect for my projectle motion code. it hasnt been working, can anyone help me out?
thanks!
clear , clc
g=9.8;
ang=input('Enter incident angle: ');
if (ang<=0)
disp('Illegal Input')
end
v=input('Enter speed(m/s): ');
if (v<=0)
disp('Illegal Input')
end
disp('enter air resistance below. If you enter 0 or a negative number, it will be automatically .5')
disp('To find the coeficient of air resistace multiply air density, drag,area times .5')
air=input('Enter air resitiance (Will otherwise be .5): ');
if air<=0,' ';
air=.5;
end
vx0=v*cosd(ang)-air*cosd(ang);%Calculation fro air resitance
vy0=v*sind(ang)-air*sind(ang);
t=(0:.01:10000);
height=vy0*t-.5*g*t.^2;
land=find(height>=0);
time=(land(end)-1)/100;
dist=vx0*time;
height2=max(height);
fprintf('Distance is %g m \n',dist);
fprintf('Max Height is %g m \n',height2);
fprintf('Time was %g sec \n ',time);
time2=t(land);
height3=height(land);
vxst=v*cosd(ang);
vyst=v*sind(ang);
heightst=vyst*t-.5*g*t.^2;
landst=find(heightst>=0);
timest=(landst(end)-1)/100;
distst=vxst*timest;
height2st=max(heightst);
time2st=t(landst);
height3st=heightst(landst);
plot(time2,height3)
hold on
plot(time2st,height3st)
xlabel('Time (Seconds)')
ylabel('Height (Meters)')
4 Comments
Walter Roberson
on 17 Apr 2020
You do need a loop for animation, unless you use comet() [which uses a timer.]
Accepted Answer
Geoff Hayes
on 21 Apr 2020
Kristian - if you want to plot t versus heightst then you could add the following to the end of your code. A stepSize of 100 is used since t is a 1x100000 array.
figure;
hPlot = plot(NaN,NaN, 'b');
xlim([min(t) max(t)]);
ylim([min(heightst) max(heightst)]);
stepSize = 100;
for k = 1:stepSize:length(t)
set(hPlot, 'XData', [get(hPlot,'XData') t(k:k+stepSize-1)], 'YData', [get(hPlot,'YData') heightst(k:k+stepSize-1)]);
pause(0.001);
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Animation 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!