Combining chart for comparison got error

조회 수: 1 (최근 30일)
Hai Nguyen
Hai Nguyen 2021년 3월 28일
댓글: Hai Nguyen 2021년 3월 30일
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?

채택된 답변

dpb
dpb 2021년 3월 28일
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
Hai Nguyen
Hai Nguyen 2021년 3월 29일
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')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by