# Overlaying Plots from 2 different sections of code

조회 수: 21(최근 30일)
답변: 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 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 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