2013-04-24 3 views
0

잘 작동하고 올바른 출력 데이터를 제공하는이 while 회 돌이가 있지만 마지막 데이터 포인트 만 저장하므로 어떻게 모든 루프 데이터를 벡터에 저장할 수 있습니까?벡터에 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 

정말 감사드립니다!

답변

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 
+0

와우, 완벽하게 충분히 감사 할 수 없습니다. – ErkNis