方法
方法的语法、属性和用途
方法是由类定义的操作。方法可以重载 MATLAB® 函数以对类的对象执行操作。MATLAB 根据主导参数来确定要调用的方法或函数。类构造函数方法创建类的对象,并且必须符合特定的规则。
类
meta.method | 关于类方法的信息 |
主题
方法使用
- 类设计中的方法
不同种类的方法在 MATLAB 类中执行不同的特定任务。 - 定义类方法和函数
在methods
代码块中定义方法,该代码块为其中定义的所有方法指定属性。 - 方法调用
MATLAB 使用主导参数来决定调用哪个方法。 - Method Access List
Specify a list of classes that can access a class method. - Object Precedence in Method Invocation
MATLAB dispatches to a specific method or function based on the dominant argument. There are rules that determine which argument is the dominant argument. - 在单独文件中定义方法
为了方便和高效,可以在单独的文件中定义类方法。
方法类型
- 方法特性
方法特性用来控制方法的行为。 - Ordinary Methods
Define ordinary methods within the class definition file using method blocks. - 类构造函数方法
类构造函数是一个创建类实例的特殊方法。 - 静态方法
静态方法不需要类的对象作为输入参数。 - Class Methods for Graphics Callbacks
There is a specific syntax necessary to use a method of your class as a callback for MATLAB graphics objects.
重载函数的方法
- 在类定义中重载函数
通过为您的类重载 MATLAB 函数,该类的对象可以支持 MATLAB 运算。 - Dominant Argument in Overloaded Graphics Functions
If you want to define a method that accepts a MATLAB graphics object as the first arguments, specify the relative precedence of your class with respect to the graphics class. - Class Support for Array-Creation Functions
Add support for array-creation functions without overloading these functions in your class. - Objects In Conditional Statements
Enable the use of objects in conditional statements by defining relational operators for the class of the object.