Combining charts for comparison

조회 수: 21 (최근 30일)
Hai Nguyen
Hai Nguyen 2021년 3월 30일
댓글: Hai Nguyen 2021년 3월 30일
I want to combine 4 charts as per attached. The charts are extracted from running the attached code by changing K, C between 0 and 1. But the result shows 1 chart only. How to fix please?
Code to combine:
if true
fig = figure(10);
ax = axes(fig);
xlabel('\tau');
ylabel(' \Psi(0,\tau)');
title('Injection rate vs. K, C');
h1 = openfig('K0C0.fig','reuse');
h2 = openfig('K0C1.fig','reuse');
h3 = openfig('K1C0.fig','reuse');
h4 = openfig('K1C1.fig','reuse');
copyobj(h1.Children.Children,ax);
copyobj(h2.Children.Children,ax);
copyobj(h3.Children.Children,ax);
copyobj(h4.Children.Children,ax);
close(h1);
close(h2);
close(h3);
close(h4);
savefig('ratevsKC');
end
hold on
legend('K=0,C=0','K=0,C=1','K=1,C=0','K=1,C=1','location', 'southeast')
Combined result:
  댓글 수: 2
Hai Nguyen
Hai Nguyen 2021년 3월 30일
I tried. In my case it showed blank in the combined figure.

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

채택된 답변

KSSV
KSSV 2021년 3월 30일
if true
fig = figure(10);
ax = axes(fig);
xlabel('\tau');
ylabel(' \Psi(0,\tau)');
title('Injection rate vs. K, C');
h1 = openfig('K0C0.fig','reuse');
h2 = openfig('K0C1.fig','reuse');
h3 = openfig('K1C0.fig','reuse');
h4 = openfig('K1C1.fig','reuse');
% GEt x and y data from figure
x1 = zeros(length(h1.Children.Children),1) ;
y1 = zeros(length(h1.Children.Children),1) ;
for i = 1:length(h1.Children.Children)
x1(i) = h1.Children.Children(i).XData ;
y1(i) = h1.Children.Children(i).YData ;
end
close(h1);
x2 = zeros(length(h2.Children.Children),1) ;
y2 = zeros(length(h2.Children.Children),1) ;
for i = 1:length(h2.Children.Children)
x2(i) = h2.Children.Children(i).XData ;
y2(i) = h2.Children.Children(i).YData ;
end
close(h2);
x3 = zeros(length(h3.Children.Children),1) ;
y3 = zeros(length(h3.Children.Children),1) ;
for i = 1:length(h3.Children.Children)
x3(i) = h3.Children.Children(i).XData ;
y3(i) = h3.Children.Children(i).YData ;
end
close(h3);
x4 = zeros(length(h4.Children.Children),1) ;
y4 = zeros(length(h4.Children.Children),1) ;
for i = 1:length(h4.Children.Children)
x4(i) = h4.Children.Children(i).XData ;
y4(i) = h4.Children.Children(i).YData ;
end
close(h4);
figure
plot(x1,y1,'-*r',x2,y2,'-sk',x3,y3,'-ob',x4,y4,'-dc');
savefig('ratevsKC');
legend('K=0,C=0','K=0,C=1','K=1,C=0','K=1,C=1','location', 'southeast')
end
  댓글 수: 1
Hai Nguyen
Hai Nguyen 2021년 3월 30일
Thank you very much for the help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by