Seitz
Seitz

Reputation: 11

Matlab GUI axes to figure

I have a Gui with some axes. Now i will put the one axes to a new figure. Here is my code:

h = handles.axes3; % Find the axes object in the GUI
f1 = figure % Open a new figure with handle f1
s = copyobj(h,f1); % Copy axes object h into figure f1
print(f1,'-dpsc', 'raspberry.eps');

this works, but the window have not the same size as the figure. I think the axes from the GUI is not on the axes1 in the new figure?

Upvotes: 1

Views: 1725

Answers (1)

matlabgui
matlabgui

Reputation: 5672

You have copied the axes, not the figure.

Creating a new figure will create one which is the default size - which is not nesessarily the same size as the ancestor(figure) of handles.axes3.

See the example below:

f = figure ( 'position', [100 100 200 200] );
h = axes ( 'position', [0 0 0.5 0.5], 'parent', f );

% This will create a figure with a different size
f1 = figure ( 'Name', 'Different Size Fig' );
copyobj ( h, f1 );

% copy a figure which has the same size as the original
hFig = ancestor ( h, 'figure' );
originalFigPos = get ( hFig, 'position' );
f2 = figure ('Name', 'Same Size Fig' );
newFigPos = get ( f2, 'position' );
newFigPos(3:4) = originalFigPos(3:4);
set ( f2, 'position', newFigPos );

s = copyobj ( h, f2 );

Upvotes: 1

Related Questions