Main Content

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 OperatorMATLAB Method
+ (binary) op_Addition plus, +
- (binary) op_Subtraction minus, -
* (binary) op_Multiplymtimes, *
/op_Divisionmrdivide, /
&&op_LogicalAndand, &
||op_LogicalOror, |
==op_Equalityeq, ==
>op_GreaterThangt, >
<op_LessThanlt, <
!=op_Inequalityne, ~=
>=op_GreaterThanOrEqualge, >=
<=op_LessThanOrEqualle, <=
- (unary)op_UnaryNegationuminus, -a
+ (unary)op_UnaryPlusuplus, +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