Clear Filters
Clear Filters

Figures don't resize, but axes do (with almost the same commands)

1 view (last 30 days)
I resize axes to a certain resolution (seconds per centimetre) and I try to resize the figure's size accordingly. The figure won't resize properly with the following code. You can see the axes fall out of the figure's drawable area (the title and a portion of the upper axes area aren't visible). What am I doing wrong or how could I fix this issue?
EDIT: Additional info: If you add
close all
in front of the code below, I get a different and still erroneous result. The figure doesn't resize at all in this case. It remains at it's default size (which I've set in startup.m), but does move to the bottom left corner of the screen.
t = 0:100;
y = t;
% resolutions
rt = 10; % s/cm
ry = 10; % [y]/cm
plot(t,y);
title 'y vs. t'
xlabel 'time, [t] = s'
ylabel 'y'
% adjust axes and figure size
f = gcf;
a = gca;
f.Units = 'centimeters';
a.Units = 'centimeters';
f.OuterPosition(1:2) = 0; % move to bottom left corner of screen
ad = a.Position(3:4); % axes dimensions
% resize to set resolution
aw = range(t)/rt; % axes width
ah = a.YLim(2)/ry; % axes height
dd = [aw ah] - ad; % dimension difference
a.Position(3:4) = [aw ah]; % new axes dimensions
f.Position(3:4) = f.Position(3:4) + dd; % new figure dimensions
I'm on R2015a and Windows 8 x64.

Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!