MATLAB: How do you print data from a loop into a Matrix

loopMATLABprinting

I am running a program that aims to simulate the flight of a rocket and it involves running a loop that simulates the rocket at x times (.0001,.0002,etc.). I need to be able to take the data from the loop not at each time interval, but every ten time intervals ie .001,.002,etc.
Originally I attempted to place an "if" statement within the loop, defining deltat as a array of values ranging from 0 to 100 at intervals of .001, but I keep receiving an error that claims that the left side is an invalid target for assignment. Is there a better way to go about doing this?
while mwater > 0
Vair = Vbottle - (mwater/rhowater)
Pair = (mairini * R * T)/(Mair * Vair)
mdotwater = .01
mwater = mwater - (mdotwater * deltat)
mtotal = mrocket + mwater + mairini
vwater = C*(2*(Pair-Patm)/(rhowater))^(.5)
Fthrust = mdotwater * vwater
Fgravity = (mtotal * 9.81)
Fdrag = (.5)*(Cd)*(rhoatm)*(Aprojected)*(vrocket)^2
Fnet = Fthrust - Fgravity - Fdrag
arocket = (Fnet)/(mtotal)
deltat = deltat + .0001;
end

Best Answer

You always write in the same cell, that's the issue. Before the while loop, define a variable to count how many times you print, e.g., counter = 0; Then, each time the if statement is true, increment it:
counter = counter + 1;
Then replace
xlswrite('stuff.xlsx',arocket,1,'A1')
with
xlswrite('stuff.xlsx',arocket,1,['A',num2str(counter)])
In that way you print in a new cell each time.