How can I run code just once, for multiple intervals of numbers?

2 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Bruno Luong
Bruno Luong il 4 Ott 2024

Più risposte (0)

Categorie

Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by