How to make a while loop to repeat multiple times with different values of variable?

2 ビュー (過去 30 日間)
Tomass
Tomass 2022 年 11 月 24 日
コメント済み: Tomass 2022 年 11 月 26 日
I would like to repeat my while loop multiple times, each time with different q value (q changes from 0.5 to 4). In my example q=0. For q=0 I got one curve in a plot. How can I get the plot with multiple curves, each corresponding to different q value.
t_in_before=19;
q=0.9;
t_out=-1;
time=0;
while t_in_before>5
t_in_after=t_in_before + (q*t_out)/154 - (q*t_in_before)/154;
time=time+1;
t_in_before=t_in_after;
plot(time,t_in_after,'b.-')
hold on
end

採用された回答

Jan
Jan 2022 年 11 月 24 日
編集済み: Jan 2022 年 11 月 24 日
Simply add a loop to modify q:
for q = 0.5:4
t_in_before=19;
t_out=-1;
time = 0;
while t_in_before > 5
t_in_after=t_in_before + (q*t_out)/154 - (q*t_in_before)/154;
time=time+1;
t_in_before=t_in_after;
plot(time,t_in_after,'b.-')
hold on
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by