Using a previously calculated value in a for loop
古いコメントを表示
I am attempting to calculate the volume over time of a basin of water given the inflow and outflow rates. With this, I am attempting to code a for loop that uses the previous calculated of the volume as the volume in the next iteration. The code I have written does not do this, it causes the loop to run continuously. the code I've attempted to make work is this: clear all; close all v=200; t=0:10;
for t<=240 vout=v+t.*(10-.1.*v) v=vout end
Any help would be greatly appreciated.
回答 (1 件)
Wayne King
2013 年 9 月 29 日
編集済み: Wayne King
2013 年 9 月 29 日
You have not written a valid MATLAB for loop. I'm not sure what you are trying to do because you create t as a vector and then don't index in the for loop. Then you try to test t <=240 but t never goes beyond 10. So I just have to guess at what you're trying to do with the for loop
v = 200;
for t = 1:240
vout(t) = v+t*(10-.1*v);
v = vout(t);
end
カテゴリ
ヘルプ センター および 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!
