How can I run code just once, for multiple intervals of numbers?
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!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! 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! if statement, for loop MATLAB Answers — New Questions