Plot two figures in one figure

조회 수: 5 (최근 30일)
Praveen Choudhury
Praveen Choudhury 2016년 2월 1일
댓글: Antonio Tavares 2020년 3월 31일
I have my own function called 'histogram_with_mean_sigma_lines'. The output of the function is a figure. So I use this function to generate two figures (which is a histogram). I want the two figures to be in one figure like two subplot (2,1,1 & 2,1,2).

채택된 답변

Star Strider
Star Strider 2016년 2월 1일
It is not straightforward but it is definitely possible:
d1 = rand(10,1); % Create Data
d2 = rand(20,1)+1; % Create Data
figure(1)
plot(d1) % First Plot
ax1 = gca;
figure(2)
plot(d2) % Second Plot
ax2 = gca;
f3 = figure(3); % Copy Axes To Subplots
ax1_copy = copyobj(ax1,f3);
subplot(2,1,1,ax1_copy)
ax2_copy = copyobj(ax2,f3);
subplot(2,1,2,ax2_copy)
Run this to see that it works, then make the appropriate changes to your code to plot both histograms in the subplots.
  댓글 수: 3
Star Strider
Star Strider 2016년 2월 1일
My pleasure!
Antonio Tavares
Antonio Tavares 2020년 3월 31일
That was a life savior!! Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-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