MATLAB: How to change the subplot positioning in an existing figure

axisfigureMATLABreplotsubplot

Dear experts,
a while ago I created a figure with two subplots in the configuration subplot(1,2,x) (one row, two columns). I saved the figure as 'fig' file for later use. Now I would prefer the plots to be in subplot(2,1) (two rows, one column) configuration. I only have the .fig file and have no access to the relevant data to replot the figure.
Is there a way the accomplish this?
I opened the figure and tried the following:
hF = gcf;
hSub11 = subplot(1,2,1);
hSub12 = subplot(1,2,2);
nF = figure;
hSub21 = subplot(2,1,1);
copyobj(allchild(hSub11),hSub21)
hSub22 = subplot(2,1,2);
copyobj(allchild(hSub12),hSub22)
But besides the legends, titles and axis labels are missing, the plots show white spaces on top and bottom or left and right of the figure, especially when being resized.
Does anyone have an advice or an overall better solution for me?
Thank you very much! (I am using MATLAB 2014b)

Best Answer

This swaps the positions of the two axes:
hFig = gcf;
hAxes = findobj(allchild(hFig), 'flat', 'Type', 'axes');
axesPos = get(hAxes, 'Position');
set(hAxes(1), 'Position', axesPos{2});
set(hAxes(2), 'Position', axesPos{1});
[EDITED] Thismove the first axes to the subplot(2,1,1) position, the 2nd to (2,1,2):
hFig = gcf;
hAxes = findobj(allchild(hFig), 'flat', 'Type', 'axes');
hSub = subplot(2,1,1);
set(hAxes(1), 'Position', get(hSub, 'Position'));
delete(hSub);
hSub = subplot(2,1,2);
set(hAxes(2), 'Position', get(hSub, 'Position'));
delete(hSub);
Please try it and explain, how the legends, white spaces etc. are effects.
Did you try to use the property editor? Open the figure, activate the toolbar, click on the arrow and move the objects around or resize with the mouse.