How to Limit figure size?
15 次查看(过去 30 天)
显示 更早的评论
The minimum size should be constant but I have been unable to achieve this. I read some stuff but nothing seems to work properlly. Any help would be apreciated.
0 个评论
回答(3 个)
Kelly Kearney
2015-12-17
If you're using a recent version of Matlab, you can accomplish this via the SizeChangedFcn of the figure:
h = figure;
figszfun = @(~,~) set(h, 'position', max([0 0 200 200], h.Position));
h.SizeChangedFcn = figszfun;
In this example, the figure will be always be at least 200 x 200 pixels.
For older versions (pre-2014b), the same thing can be accomplished via the ResizeFcn.
3 个评论
Kelly Kearney
2015-12-18
Hmm, good question, Jan, but recursion doesn't seem to be a problem, at least not on my system. I do get the flicker effect if I manually resize the figure smaller than the limit, since the mouse-set size and resize function are fighting each other, but that stops as soon as I release the mouse click.
Perhaps that's the difference between ResizeFcn and the newer SizeChangedFcn? I really haven't looked into it much.
Chad Greene
2015-12-17
Try setting the figure position in the form [xll yll width height] where xll and yll are the x and y positions of the lower left corner of the figure and width and height are, well, the width and height of the figure. Units are in pixels.
set(gcf,'pos',[10 10 300 200])
0 个评论
Jan
2015-12-18
This FEX submission is updated soon to support modern Matlab versions: http://www.mathworks.com/matlabcentral/fileexchange/38527-limit-figure-size
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!