pause button not working

조회 수: 9 (최근 30일)
Kristian Dolghier
Kristian Dolghier 2020년 4월 16일
답변: Geoff Hayes 2020년 4월 21일
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
darova
darova 2020년 4월 17일
Yes i know. But the title says button
Walter Roberson
Walter Roberson 2020년 4월 17일
You do need a loop for animation, unless you use comet() [which uses a timer.]

댓글을 달려면 로그인하십시오.

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 21일
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개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by