How to stop the program and store the scalar variable and rerun the program and plot scalar against scalar

Hi, I want to plot scalar value (t) against scalar (alpha). But it does not plot.
Simplified code is below:
da = 0.1
for i=1:31;
alpha = (1-1)*da
...
for nt=1:30001;
t=t+dt
...
if (gap2 < 10^(-8)) |(gap2 < 10^(-8))
plot (t,alpha)
break
end
end
Thanks

 Accepted Answer

Hey,
As I can understand from your code, you have alpha = 0, no?
And another thing is that you want to plot each point at each iteration, right? You should try to use the "hold on" command, for the plot function "overwrite" in the first opened plot the next points. Maybe you should save the points in vectors, and plot it outside the external cycle for.
Greets

5 Comments

I am now editing my question. I forgot to state
da .
Many thanks for the answer. how can I save the points as vectors?
da = 0.1;
alpha(1) = 0;
t(1) = 0;
for i=1:31;
alpha = (1-1)*da
...
for nt=1:30001;
t(i+1) = t(i) + dt
...
if (gap2 < 10^(-8)) |(gap2 < 10^(-8))
break
end
end
end
plot (t,alpha)
You just have to define the first the elements of alpha and t to zero, as I show here. Than at each iteration you save the newvalues. The points are afterwards plotted and the external for is finished.
I don't understand your code, maybe because there are hidden parts, but alpha is still 0...
*"The points are afterwards plotted when the external for is finished"
Pay attention to your for-end pairs
Thanks for the answer. I have used alpha in a for loop.
It is supposed to go back and increase the alpha.
In the meantime why did not you use plot command inside if condition.
I need that condition to plot t and alpha and stop the program when
gap1 or gap2 goes to zero and then go back, change new alpha rerun the program
until gap1 or gap2 goes to zero and plot new alpha against t on which we stopped the program.
Okay, I understand what do you mean about the plotting, but in any case you have to use "hold on".
In any case, I still don't know how alpha, alpha = (1 - 1)*da, should increase at each iteration.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 4 Mar 2015

Commented:

on 4 Mar 2015

Community Treasure Hunt

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

Start Hunting!