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

7 ビュー (過去 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.
  1 件のコメント
darova
darova 2019 年 12 月 17 日
Show the entire code

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

回答 (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 Center および File Exchange2-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