How can I put existing figures in different subplots in another figure in MATLAB 6.5 (R13)?

조회 수: 336 (최근 30일)
I want to make several plots, each in their own figure. I then want to create a final figure which contains subplots which have the contents of the original figures.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2010년 9월 8일
The ability to make subplots from a set of figures interactively has been incorporated in MATLAB 7.2 (R2006a) using 'Plot Tools'. To do this, perform the following steps:
1. Plot a figure.
2. Click on the white icon, "Show Plot Tools and dock figure", on the top of the figure.
3. Select all objects by pressing CTRL-A
4. Copy the objects by pressing CTRL-C
5. Open a new figure window in Plot Tools by clicking on the white icon, "New Figure" on the left.
6. Paste the objects by pressing CTRL-V
7. Repeat the steps 1-4 for the other figures you want to copy and paste them into the final figure.
The sub-plots in the final figure can now be resized and moved as desired.
To work around this issue in previous releases, read the following:
The COPYOBJ function will allow you to copy objects between parent objects. In order to copy several sets of axes into a subplot, you will need to use two steps:
1. Copy the contents of your original figure into your destination figure.
2. Modify the position properties of the axes so that they match a subplot's position. Following is an example code which should help you to set the position property. This code is designed only to work with a 4-by-1 set of subplots. You may need to modify the code to work with your data.
% First, create 4 figures with four different graphs (each with a
% colorbar):
figure(1)
surf(peaks(10))
colorbar
figure(2)
mesh(peaks(10))
colorbar
figure(3)
contour(peaks(10))
colorbar
figure(4)
pcolor(peaks(10))
colorbar
% Now create destination graph
figure(5)
ax = zeros(4,1);
for i = 1:4
ax(i)=subplot(4,1,i);
end
% Now copy contents of each figure over to destination figure
% Modify position of each axes as it is transferred
for i = 1:4
figure(i)
h = get(gcf,'Children');
newh = copyobj(h,5)
for j = 1:length(newh)
posnewh = get(newh(j),'Position');
possub = get(ax(i),'Position');
set(newh(j),'Position',...
[posnewh(1) possub(2) posnewh(3) possub(4)])
end
delete(ax(i));
end
figure(5)
  댓글 수: 2
KAE
KAE 2019년 2월 6일
편집: KAE 2020년 2월 14일
Can you update these instructions for R2019b?
Walter Roberson
Walter Roberson 2023년 8월 25일
@Megna Hari comments:
This doesnt work for an mxn layout where n>1.
it should be this but theres some reputation points requirement now so I cant post:
set(newh(j),'Position',[possub(1)+(posnewh(1)*possub(3)), possub(2)+(posnewh(2)*possub(4)), posnewh(3)*possub(3), posnewh(4)*possub(4)])

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

추가 답변 (1개)

Eric Sargent
Eric Sargent 2020년 12월 9일
Starting in R2019b, you can use tiledlayout to manage several axes. You can reparent each of your axes into a layout, and set the tile number of each axes as appropriate.
% Get a list of all of the open figures
figlist=get(groot,'Children');
newfig=figure;
tcl=tiledlayout(newfig,'flow')
for i = 1:numel(figlist)
figure(figlist(i));
ax=gca;
ax.Parent=tcl;
ax.Layout.Tile=i;
end
  댓글 수: 3
Eric Sargent
Eric Sargent 2021년 1월 19일
What do you mean by "keep the names"? What are you looking to do?

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by