plot(hs.ax,theta,y);
end
function resizeui(hObject,event)
% Get figure width and height
figwidth = hs.fig.Position(3);
figheight = hs.fig.Position(4);
% Set button position
bheight = 30;
bwidth = 70;
bbottomedge = figheight - bheight - 50;
bleftedge = 10;
hs.btn.Position = [bleftedge bbottomedge bwidth bheight];
% Set axes position
axheight = .75*figheight;
axbottomedge = max(0,figheight - axheight - 30);
axleftedge = bleftedge + bwidth + 30;
axwidth = max(0,figwidth - axleftedge - 50);
hs.ax.Position = [axleftedge axbottomedge axwidth axheight];
end
end
The resizeui function sets the location and size of the button and axes whenever the
user resizes the window:
- The button height, width, and left edge stay the same when the window resizes.
- The bottom edge of the button, bbottomedge, allows 50 pixels of space between the
top of the figure and the top of the button. - The value of the axes height, axheight, is 75% of the available height in the figure.
- The value of the axes bottom edge, axbottomedge, allows 30 pixels of space between
the top of the figure and the top of the axes. In this calculation, the max function limits
this value to nonnegative values. - The value of the axes width, axwidth, allows 50 pixels of space between the right side
of the axes and the right edge of the figure. In this calculation, the max function limits
this value to nonnegative values.
Notice that all the layout code is inside the resizeui function. It is a good practice to
put all the layout code inside the SizeChangedFcn callback to ensure the most accurate
results.
9 Lay Out a Programmatic UI