How can I run code just once, for multiple intervals of numbers?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Noob
el 4 de Oct. de 2024
Respondida: Bruno Luong
el 4 de Oct. de 2024
Let's say I want to calculate things for alpha ranging from 0 to 2pi.
I've written if / else-if statements to do this:
alpha = linspace(0, 2pi, 100)
if 0 <= alpha & alpha <= pi/2
calculate this;
elseif pi/2 < alpha & alpha < pi
calculate this;
end
Now, after I've finished debugging this code, I noticed I can only run the code for one, specific interval of alpha at a time.
So, I have to use
alpha = linspace(0, pi/2, 15),
then run code, plot data, press hold on, and then switch to
alpha = linspace(pi/2 + 1e-10, pi, 15),
then run code, plot data, press hold on, and then switch alpha intervals yet again.
This will be quite error prone, as my modeling work builds up in complexity.
So, how can I run code just once, to get all calculations, for all alpha?
If I try to run code just once, for all alpha, the code doesn't run.
I have to go one interval of alpha at a time, for the code to run.
Thanks in advance!
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!