Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 将while循环数据保存到向量中_Matlab_Vector_While Loop - Fatal编程技术网

Matlab 将while循环数据保存到向量中

Matlab 将while循环数据保存到向量中,matlab,vector,while-loop,Matlab,Vector,While Loop,我有一个while循环,它运行良好并给出正确的输出数据,但当它结束时,它只保存最新的数据点,如何将每个loopdata保存到向量中 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;

我有一个while循环,它运行良好并给出正确的输出数据,但当它结束时,它只保存最新的数据点,如何将每个loopdata保存到向量中

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
非常感谢你的帮助

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