import
Import model classes
Parent Section: none (top-level)
Syntax
import namespace_or_class; import namespace.*;
Description
The import
statements allow access to model class or function names
defined in other scopes (namespaces) without a fully qualified reference. You must place
import
statements at the beginning of a Simscape™ file.
There are two types of import
statement syntaxes. One is a
qualified import, which imports a specific namespace, class, or function:
import namespace_or_class;
The other one is an unqualified import, which imports all subnamespaces, classes, and functions under the specified namespace:
import namespace.*;
The namespace or class name must be a full path name, starting from the library root (the top-level namespace folder name) and containing subnamespace names, as necessary.
Import statements are subject to the following constraints:
The imported name must be a full path name, starting from the library root, even if the
import
statement is used in a component class defined under the same namespace as the domain or component class that is being imported.You must place
import
statements at the beginning of a Simscape file. The scope of imported names is the entire Simscape file, except thesetup
section.In qualified import statements, the imported name can refer to a subnamespace, a model class (domain class or component class), or a function. For example, in the
import A.B.C;
statement,C
can be either a subnamespace name, a class name, or a function name. In unqualified import statements, the imported name must refer to a namespace or subnamespace. For example, in theimport A.B.*;
statement,B
must be a subnamespace name (of namespaceA
).It causes a compilation error if an unqualified imported name is identical to other names within the same scope, provided the duplicate name is in use. For example, assume that subnamespaces
A.B
andA.B1
both contain a component classC
. This code:import A.B.C; import A.B1.*; component M components (ExternalAccess=observe) c = C; end end
causes a compile-time error. However, the following code is legal (provided that
D
is defined only inA.B
) becauseC
is not used:import A.B.C; import A.B1.*; component M components (ExternalAccess=observe) d = D; end end
This code is also legal:
import A.B; import A.B1; component M components c1 = B.C; c2 = B1.C; end end
because you import two different names into this scope (
B
andB1
), and access the two different component classesC
through their parent classesB
andB1
.
Examples
Version History
Introduced in R2013b