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 commentaires

darova
darova le 17 Avr 2020
I don't see any pause buttons. You don't use for loop also. How do you want to animate without loops?
Image Analyst
Image Analyst le 17 Avr 2020
darova: pause function, not pause button, but there is no call to pause() either. He should have a loop with a call to apuse inside the loop.
darova
darova le 17 Avr 2020
Yes i know. But the title says button
Walter Roberson
Walter Roberson le 17 Avr 2020
You do need a loop for animation, unless you use comet() [which uses a timer.]

Connectez-vous pour commenter.

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 21 Avr 2020

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by