Your line
atot(i)=athrust(i)-ag; % total acceleration
does not define an equation. It is executed only once, with the current value of i, so atot becomes a scalar.
Then in your line
v(i+1)=v(i)+((atot(i+1)+atot(i))/2)*dt;
on the first iteration you have the problem that atot(1+1) does not exist.
After your while loop,
nofuel_pos = find(mfuel <= 0, 1);
and then you can index your arrays at nofuel_pos or nofuel_pos - 1 as appropriate.
