How to make a while loop to repeat multiple times with different values of variable?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tomass
el 24 de Nov. de 2022
Comentada: Tomass
el 26 de Nov. de 2022
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
0 comentarios
Respuesta aceptada
Jan
el 24 de Nov. de 2022
Editada: Jan
el 24 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

