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

4 ビュー (過去 30 日間)
Noob
Noob 2024 年 10 月 4 日
回答済み: Bruno Luong 2024 年 10 月 4 日
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!

採用された回答

Bruno Luong
Bruno Luong 2024 年 10 月 4 日

その他の回答 (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