How to put existing figures in one figure together?

조회 수: 20 (최근 30일)
Mibang
Mibang 2024년 4월 14일
댓글: Voss 2024년 4월 14일
I have two existing figures ('fig1.fig" and "fig2.fig"), and want to put in one figure together horizontally and vertically (creating 2 figures).
I tried to use "tiledlayout" spending some time, but failed.
Thank you very much,
openfig('fig1.fig')
ans =
Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [268.2000 671.0000 560 420.0000] Units: 'pixels' Use GET to show all properties
openfig('fig2.fig')
ans =
Figure (2) with properties: Number: 2 Name: '' Color: [1 1 1] Position: [1325 496 560 420] Units: 'pixels' Use GET to show all properties

채택된 답변

Voss
Voss 2024년 4월 14일
% open the fig files in two new figures
f1 = openfig('fig1.fig','invisible');
f2 = openfig('fig2.fig','invisible');
% get the ConfusionMatrixChart in each figure
cmc1 = f1.Children;
cmc2 = f2.Children;
% alternate way to get the ConfusionMatrixChart in each figure
% cmc1 = findall(f1,'Type','ConfusionMatrixChart');
% cmc2 = findall(f2,'Type','ConfusionMatrixChart');
% create a new figure with a tiledlayout
f = figure();
t = tiledlayout(f,1,2);
% copy the charts into the tiledlayout
h1 = copyobj(cmc1,t);
h2 = copyobj(cmc2,t);
% place them correctly
h1.Layout.Tile = 1;
h2.Layout.Tile = 2;
% same thing, now with a vertical layout
% create a new figure with a tiledlayout
f = figure();
t = tiledlayout(f,2,1);
% copy the charts into the tiledlayout
h1 = copyobj(cmc1,t);
h2 = copyobj(cmc2,t);
% place them correctly
h1.Layout.Tile = 1;
h2.Layout.Tile = 2;
% delete the original figures
delete([f1 f2])
  댓글 수: 4
Mibang
Mibang 2024년 4월 14일
Even more perfect!
Thank you for the bonus!
Voss
Voss 2024년 4월 14일
You're welcome!

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

추가 답변 (1개)

Paul
Paul 2024년 4월 14일
If subplot layout is acceptable, then ...
% open the fig files in two new figures
f1 = openfig('fig1.fig','Invisible');
f2 = openfig('fig2.fig','invisible');
hnew = figure;
ax1 = copyobj(f1.Children,hnew);
subplot(2,1,1,ax1)
ax2 = copyobj(f2.Children,hnew);
subplot(2,1,2,ax2)
  댓글 수: 2
Mibang
Mibang 2024년 4월 14일
편집: Mibang 2024년 4월 14일
Perfect, again! This is even simpler.
Maybe bonus for me: is it possible to make the labels simpler, i.e., one "True Class" and "Predicted Class"?
Maybe not possible
Mibang
Mibang 2024년 4월 14일
I want this answer accepted too, but I cannot.
Thank you very much.

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

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by