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

 Akzeptierte Antwort

Image Analyst
Image Analyst am 24 Apr. 2015

0 Stimmen

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]

4 Kommentare

VeraM
VeraM am 25 Apr. 2015
thank you this worked :)
Kribashnee Dorasamy
Kribashnee Dorasamy am 27 Feb. 2017
Bearbeitet: Kribashnee Dorasamy am 27 Feb. 2017
Problems arise when there are two image/axes in a figure. Not only does that line change the size but also the locations. How can one rectify this?
Image Analyst
Image Analyst am 27 Feb. 2017
The first two elements, xLeft and yBottom, specify the location. What are your problems? Rectify what? Please supply simple code to illustrate the problems.
Roy Ramirez
Roy Ramirez am 30 Nov. 2022
didn't work for me. I put the axes widget inside of a Panel widget an now I can size it with GUIDE

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Adam
Adam am 24 Apr. 2015
Bearbeitet: Adam am 24 Apr. 2015

1 Stimme

Apart from the obvious point that you are calling ' get ', not ' set ', I've never used copyobj so am not really familiar with it, but you should really try to work with an explicit axes handle rather than gca which is somewhat transient. It may not be a problem here, but it can easily become a source of problems when your program gets more complicated.

3 Kommentare

VeraM
VeraM am 24 Apr. 2015
Thanks for your advice on using the axes handle instead of gca, I will see if I can get it to work that way. And yes that was a typo (my mistake!) I meant set(gca...)
Adam
Adam am 24 Apr. 2015
You may want to play around with the
OuterPosition
property of the axes too. That is the onoe that includes all the space for the title, axes ticks, labels etc etc.
VeraM
VeraM am 25 Apr. 2015
Thanks using 'outerposition' worked!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by