import
Add namespace, class, or functions to current import list
Syntax
Description
import
adds the class name to the current import list. To refer to a class without
specifying the entire namespace, use the Namespace
.ClassName
import
function in
your code.
The import list scope is defined as follows:
Functions, including nested and local functions — The scope is the entirety of the function. This includes code that precedes
import
.The import list of a function is persistent across calls to that function and is cleared only when the function is cleared. For more information, see the
clear
function. Do not callclear import
within a function or a script.Scripts — The scope of a script is the entire script body. This includes code that precedes
import
. The imports in a script are available only in the script body and are not available in the scopes which call the script. For example, executing a script containing imports at the command prompt does not make the imports available in the command window.Base workspace — The scope is code executed at the command prompt. To clear the base import list, type
clear import
at the MATLAB® command prompt.
import
adds the specified namespace-based function. Use this syntax to shorten the name
of a specific function in a namespace without importing every function in the
namespace, which might cause unexpected name conflicts.Namespace
.FunctionName
import
adds the specified static method. Use this syntax to shorten the name of a
specific static method. Namespace
.ClassName
.staticMethodName
import
adds the contents of the specified namespace identifier.
Namespace
.*Namespace
must be followed by
.*
.
Avoid using this syntax, as importing the contents of namespaces brings an unspecified set of names into the local scope, which might conflict with names in the MATLAB workspace. One possible use for this syntax is to import a partial namespace. Then when you call a function, you use a shorter namespace name which does not conflict with simple function names.
Examples
Input Arguments
Output Arguments
Limitations
import
cannot load a Java® JAR namespace created by the MATLAB Compiler SDK™ product.Do not use
import
in conditional statements inside a function. MATLAB preprocesses theimport
statement before evaluating the variables in the conditional statements.