How do you print data from a loop into a Matrix?
이전 댓글 표시
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
댓글 수: 6
Sara
2014년 4월 17일
the line
deltat = deltat + .0001;
seems to imply that deltat is not an array but a scalar... Btw, which line gives you the error and which error exactly? If you provide the input data, people may be able to reproduce your error.
Sara
2014년 4월 17일
why don't you do:
if(mod(deltat,0.001)==0)
This checks if the current deltat is a multiple of 0.001 (as you seem to need).
Image Analyst
2014년 4월 17일
You forgot to paste in your error message. You just paraphrased and snipped out a small chunk of it. We want all the red text - all of it, don't leave any out. And you also forgot to attach your data file like Sara asked for.
I'll go off on a tangent here. Using mod on doubles makes me cringe. Matlab uses forced rounding to make it work. At least from my point of view, that is unexpected behavior, and one should always be careful to read the fine print of the functions one will use. Given that Matlab is so vast, that makes for a lot of reading.
I'm done ranting for the day.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!