How to add plot in the outside with 2 for loop ?

4 visualizaciones (últimos 30 días)
Fahmy Shandy
Fahmy Shandy el 17 de Dic. de 2019
Comentada: darova el 17 de Dic. de 2019
Suppose i have 2 for loop in my script. The last for loop is continue the previous for loop and so does the plot.
And i know i can do this
for i=1:3
% some code
plot(x,y);
hold on
end
for i=4:n %n is the last iteration
% some code
plot (x,y);
hold off;
end
My plot is shows nicely, But it makes my code running slow.
And if i do this :
for i=1:3
% some code
end
plot(x,y);
hold on
for i=4:n %n is the last iteration
% some code
end
plot (x,y);
hold off;
My graph is messed up when i'm doing that and my code is running fast. But there some missing plot in a certain interval.
I want my code running fast and shows up a complete graph.
Please help me. Thanks And let me know if it's not clear.

Respuestas (2)

ME
ME el 17 de Dic. de 2019
When you are plotting inside the for loop, I'd bet you are plotting collections of 7 data points each time around the loop (i.e. the ones used in your Adams-Bashforth method). Then, when you take the plot command outside your for loop, you are only plotting the last 7 points you had. That would mean you aren't saving the old data points properly as you go along.
It is extremely hard to help you find out where exactly you have gone wront without being able to see the whole code you have used though. That means we are unable to try to run it ourselves and find out what will fix your issue.
This is also likely to be what is slowing your code down in all of your previous questions too!

Thuso Gaosenngwe
Thuso Gaosenngwe el 17 de Dic. de 2019
Hello i would like to think that the reason your second graphs not coming as expected is because its only plotting the last points that it calculated in the loop. im not sure if theres any other way to do this unless maybe you optimize the calculation but that can sometimes not give true results .

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by