import
Add package or class to current import list
Syntax
import PackageName.ClassName
import PackageName.FunctionName
import PackageName.*
import
L = import
Description
import
adds the class name to the current import list. Use thePackageName
.ClassName
import
function in your code to refer to a class without specifying the entire package name.
The import list scope is defined as follows:
Script invoked from the MATLAB®command prompt — Scope is the base MATLAB workspace.
Function, including nested and local function — Scope is the function and the function does not share the import list of the parent function. If the import list is needed in a MATLAB function or script and in any local functions, you must call the
import
function for each function.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.
To clear the current import list, typeclear import
at the MATLAB command prompt. Do not callclear import
within a function or a script.
import
adds the specified package-based function. Use this syntax to shorten the name of a specific function in a package without importing every function in the package, which might cause unexpected name conflicts.PackageName
.FunctionName
import
adds the specified package name.PackageName
.*PackageName
must be followed by.*
.
Avoid using this syntax, as importing packages 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 package name. Then when you call a function, you use a shorter package name which does not conflict with simple function names. For example, thematlab.io.hdf4.sd
package has aclose
function, which can conflict with the MATLABclose
function.
Examples
Input Arguments
Output Arguments
Limitations
import
cannot load a Java®JAR package created by theMATLAB 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.