Combining chart for comparison got error

1 Ansicht (letzte 30 Tage)
Hai Nguyen
Hai Nguyen am 28 Mär. 2021
Kommentiert: Hai Nguyen am 30 Mär. 2021
I used the code below to combine two figures as attached for comparison. The charts are extracted from the long code attached by changing the input between C=0 and C=1.
The charts:
The comparion lines:
if true
fig = figure(6);
ax = axes(fig);
xlabel('\xi');
ylabel(' \lambda(\xi,\tau)');
title('Comparions for the case K=1');
h1 = openfig('C0K1.fig','reuse');
h2 = openfig('C1K1.fig','reuse');
copyobj(h1.Children.Children,ax);
copyobj(h2.Children.Children,ax);
close(h1);
close(h2);
savefig('K1compare');
end
hold on
legend('C=0','C=1','location', 'northeast')
Error showed:
Error using copyobj
Too many input arguments.
Error in K1compare (line 9)
copyobj(h1.Children.Children,ax);
How to fix please?

Akzeptierte Antwort

dpb
dpb am 28 Mär. 2021
h1.Children.Children returns a comma-separated list--
>> h1.Children.Children
ans =
0×0 empty GraphicsPlaceholder array.
ans =
2×1 Line array:
Line ( \lambda_u = 16.0623)
Line ( Classical P3D)
>>
You can let the empty placeholder be passed by
opyobj([h1.Children.Children,ax]);
copyobj([h2.Children.Children,ax]);
More robust would be to use findobj to only return and copy the lines.
  2 Kommentare
Hai Nguyen
Hai Nguyen am 29 Mär. 2021
I tried the new lines below as instructed but still got error.
if true
fig = figure(6);
ax = axes(fig);
xlabel('\xi');
ylabel(' \lambda(\xi,\tau)');
title('Comparions for the case K=1');
h1 = openfig('C0K1.fig','reuse');
h2 = openfig('C1K1.fig','reuse');
copyobj([h1.Children.Children,ax]);
copyobj([h2.Children.Children,ax]);
close(h1);
close(h2);
savefig('K1compare');
end
hold on
legend('C=0','C=1','location', 'northeast')

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by