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:

 Réponse acceptée

KSSV
KSSV le 30 Mar 2021

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by