How do i superimpose different MATLAB figures

조회 수: 78 (최근 30일)
Kelechukwu Ezike
Kelechukwu Ezike 2018년 3월 1일
답변: Kelechukwu Ezike 2018년 3월 2일
Hi, i have these MATLAB figures and will like to superimpose them as one figure. Is there a line of code to achieve that? They both have same y and x limits

채택된 답변

Walter Roberson
Walter Roberson 2018년 3월 1일
No, there is no line of code to achieve that. Merging of figures takes a bunch of work because of all of the special cases about menus and toolbars and callbacks (and because the two figures might have been created with different MATLAB releases with different support for graphics objects.)
In the simple case where you are willing to flub all of that:
first_fig = figure(1);
second_fig = figure(2);
first_ax = findobj(first_fig, 'type', 'axes');
second_ax = findobj(second_fig, 'type', 'axes')
if length(first_ax) ~= 1 || length(second_ax) ~= 1
error('this code requires the two figures to have exactly one axes each');
end
ch2 = get(second_ax, 'children'); %direct children only and don't try to find the hidden ones
copyobj(ch2, first_ax); %beam them over

추가 답변 (3개)

Kelechukwu Ezike
Kelechukwu Ezike 2018년 3월 1일
Thanks Walter

Kelechukwu Ezike
Kelechukwu Ezike 2018년 3월 1일
Hi Walter, i tried modifying the code to superpose 3 figures but couldnt get through it. It worked perfectly for the 2 figures. Can you help out please
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 3월 1일
first_fig = figure(1); %adjust as needed
second_fig = figure(2); %adjust as needed
third_fig = figure(3); %adjust as needed
first_ax = findobj(first_fig, 'type', 'axes');
second_ax = findobj(second_fig, 'type', 'axes');
third_ax = findobj(third_fig, 'type', 'axes');
if length(first_ax) ~= 1 || length(second_ax) ~= 1 || length(third_ax) ~= 1
error('this code requires the three figures to have exactly one axes each');
end
ch2 = get(second_ax, 'children'); %direct children only and don't try to find the hidden ones
copyobj(ch2, first_ax); %beam them over
ch3 = get(third_ax, 'children'); %direct children only and don't try to find the hidden ones
copyobj(ch3, first_ax); %beam them over

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


Kelechukwu Ezike
Kelechukwu Ezike 2018년 3월 2일
Awesome. Thanks Walter

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by