How to make a subplot into a new standalone figure?

92 ビュー (過去 30 日間)
K E
K E 2014 年 2 月 27 日
コメント済み: Ash Ash 2020 年 7 月 12 日
A colleague is giving me several fig files, each of which contains several subplots. What is the way that I can "copy" a subplot to a new standalone figure, including lines, x/y labels, and title? I would like to insert this in the following code, so I can automatically generate a figure for every subplot in the workspace.
% Make some fake figures
for iFig = 1:3
for iSub = 1:4
figure(iFig);
subplot(2,2,iSub);
end
end
% Get handles to all subplots
hAx = findobj('type', 'axes');
for iAx = 1:length(hAx)
axes(hAx(iAx));
% Do something here to generate a new figure containing
% lines/labels copied from this axis
end

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 2 月 27 日
You'll want to use copyobj.
This MathWorks' TS Answer might help get you started.
  2 件のコメント
K E
K E 2014 年 2 月 28 日
Great! I was able to do the following,
hAx = findobj('type', 'axes');
for iAx = 1:length(hAx)
fNew = figure;
hNew = copyobj(hAx(iAx), fNew);
% Change the axes position so it fills whole figure
set(hNew, 'pos', [0.23162 0.2233 0.72058 0.63107])
end
Ash Ash
Ash Ash 2020 年 7 月 12 日
Thank you! This code solved my problem. All I needed to do was to tweak the axes position values to fit my monitor resolution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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