0

我有这个while循环,它运行良好并提供正确的输出数据,但它结束时只保存最新的数据点,我怎样才能将每个循环数据保存到一个向量中?

t0=0.15; % Initial time
v0=46.5285; % Initial velocity
h0=3.4896; %Initial height
dt=0.001; % Timesteps/Precision
m=0.05; %Mass
g=9.81; % The gravitational constant

Velocity2=46.5285;

t = t0;
while Velocity2>=-20
Velocity2=hastighet(acceleration(0,m,g),t,v0,t0);
Height2=hojd(acceleration(0,m,g),t,h0,v0,t0);
 t=t+dt;
end

非常感谢您的帮助!

4

1 回答 1

0
t = t0;
velocityData = [];
heightData = [];
timeData = [];
counter = 1;

while Velocity2>=-20
    Velocity2=hastighet(acceleration(0,m,g),t,v0,t0);
    Height2=hojd(acceleration(0,m,g),t,h0,v0,t0);
    velocityData(counter) = Velocity2;
    heightData(counter) = Height2;
    timeData(counter) = t;
    t=t+dt;
    counter = counter + 1;
end
于 2013-04-24T17:15:02.983 回答