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

2 ビュー (過去 30 日間)
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.
##### 1 件のコメント表示非表示 なし
darova 2019 年 12 月 17 日
Show the entire code

サインインしてコメントする。

### 回答 (2 件)

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!
##### 0 件のコメント表示非表示 -1 件の古いコメント

サインインしてコメントする。

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 .

サインインしてコメントする。

R14SP1

### Community Treasure Hunt

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

Start Hunting!

Translated by