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

11 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Jan
Jan am 24 Nov. 2022
Bearbeitet: Jan am 24 Nov. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by