How MATLAB Represents .NET Operators
MATLAB® supports overloaded operators, such as the C# operator symbols
+ and *, as shown in this table. MATLAB implements all other overloaded operators, such as %
and +=, by their static method names, op_Modulus
and op_AdditionAssignment. For .NET operator overloading usage
guidelines, refer to Microsoft® documentation.
| C++ Operator Symbol | .NET Operator | MATLAB Method |
|---|---|---|
+ (binary) | op_Addition
| plus, +
|
- (binary) | op_Subtraction
| minus, -
|
* (binary) | op_Multiply | mtimes, * |
/ | op_Division | mrdivide, / |
&& | op_LogicalAnd | and, & |
|| | op_LogicalOr | or, | |
== | op_Equality | eq, == |
> | op_GreaterThan | gt, > |
< | op_LessThan | lt, < |
!= | op_Inequality | ne, ~= |
>= | op_GreaterThanOrEqual | ge, >= |
<= | op_LessThanOrEqual | le, <= |
- (unary) | op_UnaryNegation | uminus, -a |
+ (unary) | op_UnaryPlus | uplus, +a |
To call an overloaded operator in MATLAB, use the operator symbol. For example, to compare two dates, use the
== symbol:
netDate = System.DateTime.Now; netDate.DayOfWeek == System.DateTime.Now.DayOfWeek
ans = 1
To call the .NET operator, use the static method syntax:
namespace.ClassName.MethodName(args)
For example, to use the op_Equality method, type:
System.DateTime.op_Equality(netDate,System.DateTime.Now)
ans = 0