The panels within a figure are arranged in a hierarchy (or tree). The "root panel" is attached to a Matlab graphics object (usually a figure, though see demopanelD). Each panel, including the root panel, may have one or more "child panels". This is recursive, so that the entire layout forms a hierarchical "family" of panels, including the root panel and all its descendants. This is shown in the illustration (click to enlarge).
Newly-created panels are "uncommitted", and do nothing but take up space. If you call select() on an uncommitted panel, it is committed as an "object panel" - that is, it now looks after a graphics object (if you don't pass it a graphics object, it will create an axis automatically and look after that). If you call pack() on an uncommitted panel, it is committed as a "parent panel" - that is, it now contains child panels and looks after their positioning.
Layout in Panel is governed primarily by "packing". Most panels will be packed in "relative" mode. This means that the space offered by their parent is distributed amongst them according to their packed sizes (fractions of the parent space, fixed physical sizes in millimeters or inches, or 'stretchable'). "Absolute" packing is also available - see pack(). Panels can be packed along either the horizontal or vertical dimension, so that arbitrarily complex layouts can be built.
Hint You can develop "grid" layouts very succinctly by using the syntax pack(M, N). For an example, see demopanel2.
The other lever you have for controlling layout is "margins". Every panel has a margin on each of its four edges. This margin is respected within the panel's parent. For most panels, the parent is the parent panel; for the root panel, the parent is the figure window (or the image file, if exporting).
Note that margins are respected only within the immediate parent. For example, the margin setting of the root panel affects the layout of the whole figure with respect to the figure edge, whilst the margin settings of any child panels, grandchild panels, etc., have no impact on the relationship with the figure edge.
Most likely, you will set margins using p(...).margin to set an individual relationship between an individual panel and a sibling, and p(...).de.margin to control the relationships amongst all the descendants of p.
Hint I often find it easiest to start with a small or zero margin everywhere, and then increase margins individually as necessary. For an example, see demopanel9.
Note that you can get/set margins in a variety of physical units - see the property units.