import
Adds a package or class name to the import list so it can be used with a short name.
Category: Programming > Classes
Syntax
import pkg.name
Imports one function or class from package pkg.
import pkg.*
Imports everything in package pkg.
Description
Package members are normally called by their full path, such as containers.Map(...). With import containers.Map, the shorter Map(...) is recognized in the same function or script. The list lasts until the function ends or the workspace is cleared, and the command form import pkg.name is the usual way to write it.
Importing does not load anything and cannot make an unknown name valid; it only gives the name an alias.
Input arguments
pkg.name- Fully qualified name, such as
containers.Mapormatlab.lang.makeValidName.
Example
Using the full name
import containers.Map
m = containers.Map();
m('one') = 1;
disp(m.Count)
1
Notes
The import statement is accepted, but short names are not resolved afterwards in this version. Always write the full name, as in the example.