close all;
clear all;
clc;
% height and period of time per data change
timeStep = 0.0005;
height = zeros(4e4,1);
% acceleration
g = 9.81;
% COR and initial height
COR = 0.8;
height(1)=15;
% initial speed
v = 0;
for i=2:length(height)
v = v - g*timeStep;
%new height
height(i)=max(0,height(i-1) v*timeStep);
% stop ball from going below ground
if height(i)<=0
% change velocity direction
v = -COR*v;
end
end
% plot height on y and time on x axis
time = (1:4e4)*timeStep;
plot(time,height);
% turn into animation
%z = plot(time,height,'o','markerfacecolor','r','markersize',11);
i = 0;
while 1
%set(z,'XData',time,'YData',height);
%drawnow
time2 = time(i);
height2 = height(i);
plot(time2,height2,'o','markerfacecolor','r','markersize',11);
axis([0 15 0 15]);
i = i 1;
pause(0.1);
end
grid on;
box on;
uj5u.com熱心網友回復:
我發現了一個小錯誤。您的索引i應該從 1 而不是 0 開始。除此之外,您所需要的只是用drawnow. 檔案可以在這里找到。
當您在評論中提供此方法時,我可能會建議您查看一下,
pause(0.1)因為這意味著您的影片需要超過 16 分鐘才能完成。由于時間步長,您可能沒有注意到您的圖表上有更新。
使用您注釋掉的代碼將是一種可能的解決方案。
% turn into animation
z= plot(time(1),height(1),'o','markerfacecolor','r','markersize',11);
axis([0 15 0 15]);
grid on;
box on;
for i = 2:length(height)
set(z,'XData',time(i),'YData',height(i));
drawnow limitrate
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/433140.html
上一篇:SwiftUI無法影片影像過渡
