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

조회 수: 5 (최근 30일)
Fahmy Shandy
Fahmy Shandy 2019년 12월 17일
댓글: darova 2019년 12월 17일
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.

답변 (2개)

ME
ME 2019년 12월 17일
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 2019년 12월 17일
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 .

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R14SP1

Community Treasure Hunt

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

Start Hunting!

Translated by