打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Positioning Figures
On this page…
Introduction
The Position Vector
Example — Specifying Figure Position
Introduction
The figure Position property controls the size and location of the figure window on the screen. Monitor screen size is a property of the rootHandle Graphics? object. At startup, the MATLAB? software determines the size of your computer screen and defines a default value forPosition. This default creates figures about one-quarter of the screen's minimum extent and places them centered left to right, in the top half of the screen.
The Position Vector
MATLAB defines the figure Position property as a vector.
[left bottom width height]left and bottom define the position of the first addressable pixel in the lower left corner of the window, specified with respect to the lower left corner of the screen. width and height define the size of the interior of the window (i.e., exclusive of the window border).
MATLAB does not measure the window border when placing the figure; the Position property defines only the internal active area of the figure window.
Because figures are windows under the control of your computer's windowing system, you can move and resize figures as you would any other windows. MATLAB automatically updates the Position property to the new values.
Figure Position and Window Managers
Your computer's window manager controls the layout of windows on monitors and on virtual desktops. It might not honor a request to place a figure window that would cause the entire figure or its top border to be located off-screen. A window manager also might force windows to have a certain minimum or maximum width or height. Such actions can cause a figure's position to differ from what you specify, and results can vary across platforms and window managers.
Figure Position for Docked Figures
When a figure is docked in the MATLAB desktop, the Position property is defined with respect to the figure group container within the desktop. See Docking Figures in the Desktop for more information.
Units
The figure's Units property determines the units of the values with which you specify its position on the screen. Possible values for theUnits property are
set(gcf,'Units')[ inches | centimeters | normalized | points | {pixels} | characters]with pixels being the default. These choices allow you to specify the figure size and location in absolute units (such as inches) if you want the window always to be a certain size, or in units relative to the screen size (such as pixels).
Characters are units that enable you to define the location and size of the figure in units that are based on the size of the default system font.
Determining Screen Size
Whatever units you use, it is important to know the extent of the screen in those units. You can obtain this information from the rootScreenSize property. For example:
get(0,'ScreenSize')ans = 1 1 1152 900In this case, the screen is 1152 by 900 pixels. MATLAB returns the ScreenSize in the units determined by the root Units property. For example,
set(0,'Units','normalized')normalizes the values returned by ScreenSize.
get(0,'ScreenSize')ans = 0 0 1 1MATLAB determines the screen size in absolute units (e.g., inches) by dividing the number of pixels in width and height by the screen DPI (see the ScreenPixelsPerInch property). This value is approximate and might not represent the actual size of the screen.
Defining the figure Position in terms of the ScreenSize in normalized units makes the specification independent of variations in screen size. This is useful if you are writing a MATLAB file to use on different computer systems. It does, however, result in differently-shaped figures on monitors having different aspect ratios.
The ScreenSize property is static. Its values are read only at MATLAB startup and not updated if system display settings change. Also, the values returned might not represent the usable screen size for application developers due to the presence of other GUIs, such as the Microsoft? Windows? taskbar.
Example — Specifying Figure Position
Suppose you want to define two figure windows that occupy the upper third of the computer screen (e.g., one for uicontrols and the other for displaying data). To position the windows precisely, you must take into account the window borders (which can include a menu bar and toolbars) when calculating the size and offsets. For this purpose, use the windows' OuterPosition rather than their Position property.
Ensure root units are pixels and get the size of the screen and create a figure window:
set(0,'Units','pixels') scnsize = get(0,'ScreenSize');fig1 = figure;
The figure Position property only includes the drawable extent of the window, exclusive of the window borders. Obtain the entire window's size from the OuterPosition property, and compare the two:
position = get(fig1,'Position')outerpos = get(fig1,'OuterPosition')borders = outerpos - positionposition = 560 528 560 420outerpos = 556 524 568 495borders = -4 -4 8 75The left, right, and bottom borders are each 4 pixels wide. The top border, which contains a menu bar and a figure toolbar is 75-4, or 71 pixels wide.
Create a second figure, which defaults to the same size as the first one:
fig2 = figure;
Define the desired size and location of the figures. Leave a space equal to their border width between them:
edge = -borders(1)/2;pos1 = [edge,... scnsize(4) * (2/3),... scnsize(3)/2 - edge,... scnsize(4)/3];pos2 = [scnsize(3)/2 + edge,... pos1(2),... pos1(3),... pos1(4)];
Reposition the two figures by changing both of their OuterPosition properties:
set(fig1,'OuterPosition',pos1) set(fig2,'OuterPosition',pos2)
The two figures now occupy the top third of the screen.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
7 Killer Tools To Improve Your Windows 8 Experience
你不知道的极致MATLAB仿R制图工具箱
在U3D中生成Cubemap所需要的六面图
新目标九年级units1-15重点单词
九年级1--15单词汉译英
unity3d GUI 自适应分辨率
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服