Get all top-level packages
P = meta.package.getAllPackages
P = meta.package.getAllPackages is a static method that returns a cell array of meta.package objects representing all the top-level packages that are visible on the MATLAB® path or defined as top-level built-in packages. You can access subpackages using the Packages property of each meta.package object.
Note that the time required to find all the packages on the path might be excessively long in some cases. You should therefore avoid using this method in any code where execution time is a consideration. getAllPackages is generally intended for interactive use only.