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

264 ビュー (過去 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 Center および File ExchangeSubplots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by