MATLAB: Resize axes in figure Matlab

matlab figure resize axes

I have a button in my Matlab GUI to open up an axes plot in a new figure, here is my code:
fig=figure;
set(fig, 'Position', [100, 100, 1049, 895]);
h=handles.axes2;
copyobj(h,fig);
set(gca,'units','pix')
set(gca,'units','norm')
However, the axes is quite small in the new figure:
But when I try to add this line at the bottom of the previous code:
get(gca,{'Position',[100, 100, 1049, 895]}); % [left bottom right top]
nothing changes… I have tried changing the numbers as well but the axes does not get resized…
Can anyone tell me what I'm doing wrong?
Thanks

Best Answer

Set the OuterPosition of the axes, not the figure:
set(h, 'Units', 'Normalized'); % First change to normalized units.
set(h, 'OuterPosition', [.1, .1, .85, .85]); % [xLeft, yBottom, width, height]