MATLAB: Save While-loop to vector

MATLABurgentvectorizationwhile loop

I have this while loop which works very well and gives the correct output data but as it ends it only saves the latest datapoint, how can I save every loopdata into a vector?
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
Really appreciate your help!

Best Answer

Change it to the following:
VelocityVector=[];
while Velocity2>=-20
Velocity2=hastighet(acceleration(0,m,g),t,v0,t0);
VelocityVector=[VelocityVector; Velocity2];
Height2=hojd(acceleration(0,m,g),t,h0,v0,t0);
t=t+dt;
end
Then all your data is saved in VelocityVector.