フィルターのクリア

Overlaying Plots from 2 different sections of code

12 ビュー (過去 30 日間)
Braden Kerr
Braden Kerr 2020 年 10 月 29 日
回答済み: Saurav Chaudhary 2020 年 11 月 2 日
Hello,
I have a weird question. So I have a code that runs in two sections, the first section creates a set of subplots that I need along with 3 other sets of subplots. So I have 3 figures all based off of the output from this one algorythm. I then copy that entire section and run it again, but this time with a different algorithm, but it generates the same plots for this new algorithm. For my project, I really only need the first section, so if possible I dont want to go in and add the second algorithm to the first section since it would necessitate a ton more variables and work I dont have to do.
What im interested in is if it is possible to take the plots from the first section of code, and plot the second section of code on those same plots.
Ill try to write out what I mean below.
%% Section 1:
Algorithm 1
Figure (1)
.
.
.
.
Figure (2)
.
.
.
.
Figure (3)
.
.
.
%% Section 2:
Algorithm 2 (Exact same code as section one)
Figure (1)
.
.
.
.
Figure (2)
.
.
.
.
Figure (3)
.
.
.
Where I am hoping to plot Figure (3) from section 2 on the same plot as figure (3) from section one to compare how the algorithms change the output.
Again, I understand that I could include algorithm 2 in the first section and just duplicate variables and slightly change the name, but that would be a lot of work I dont need to do necessarily.
  1 件のコメント
Mathieu NOE
Mathieu NOE 2020 年 10 月 29 日
hi
unless I don't get the point, it seems fairly simple to plot two data sets , either in your last fig3 or creat a new fig for that.
first is the ouput of algo 1 and second , from algo 2
something like : plot(x_algo1,y_algo1,'b',x_algo2,y_algo2,'r'). very basic !

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

回答 (1 件)

Saurav Chaudhary
Saurav Chaudhary 2020 年 11 月 2 日
You can use "hold" to add different plots to the already existing one, it will serve the purpose of comparing how the algorithms change the output.
plot(figure 3) %algorithm 1
hold on
plot(figure 3) %algorithm 2
hold off
Find more about it in the link given below.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by