大多数运算符都是由函数表示的,是的。
MathWorks 页面上提供了完整的列表为您的类实现运算符 http://www.mathworks.com/help/matlab/matlab_oop/implementing-operators-for-your-class.html,转载于此:
a + b plus(a,b) Binary addition
a - b minus(a,b) Binary subtraction
-a uminus(a) Unary minus
+a uplus(a) Unary plus
a.*b times(a,b) Element-wise multiplication
a*b mtimes(a,b) Matrix multiplication
a./b rdivide(a,b) Right element-wise division
a.\b ldivide(a,b) Left element-wise division
a/b mrdivide(a,b) Matrix right division
a\b mldivide(a,b) Matrix left division
a.^b power(a,b) Element-wise power
a^b mpower(a,b) Matrix power
a < b lt(a,b) Less than
a > b gt(a,b) Greater than
a <= b le(a,b) Less than or equal to
a >= b ge(a,b) Greater than or equal to
a ~= b ne(a,b) Not equal to
a == b eq(a,b) Equality
a & b and(a,b) Logical AND
a | b or(a,b) Logical OR
~a not(a) Logical NOT
a:d:b colon(a,d,b) Colon operator
a:b
colon(a,b)
a' ctranspose(a) Complex conjugate transpose
a.' transpose(a) Matrix transpose
command line output display(a) Display method
[a b] horzcat(a,b,...) Horizontal concatenation
[a; b] vertcat(a,b,...) Vertical concatenation
a(s1,s2,...sn) subsref(a,s) Subscripted reference
a(s1,...,sn) = b subsasgn(a,s,b) Subscripted assignment
b(a) subsindex(a) Subscript index
另一个寻找列表的好地方实际上是文档bsxfun http://www.mathworks.com/help/matlab/ref/bsxfun.html,它应用任何具有非常强大的虚拟数据复制的逐元素函数。
经常有用的是vertcat
. 水平的 http://www.mathworks.com/help/matlab/ref/horzcat.html vs. vertical http://www.mathworks.com/help/matlab/ref/vertcat.html与逗号分隔列表的串联:
>> c = {'a','b'};
>> horzcat(c{:}) % [c{1} c{2}]
ans =
ab
>> vertcat(c{:}) % [c{1};c{2}]
ans =
a
b
除了许多其他记录的具有命名函数的运算符(colon
,transpose
等),您可以使用一些未记录的内容来访问builtin http://www.mathworks.com/help/matlab/ref/builtin.html:
插入语
>> x = [4 5 6];
>> builtin('_paren',x,[2 3]) % x([2 3])
ans =
5 6
大括号
>> c = {'one','two'};
>> builtin('_brace',c,2) % c{2}
ans =
two
结构体字段访问(点)
>> s = struct('f','contents');
>> builtin('_dot',s,'f') % s.f
ans =
contents
However,请注意正确且受支持的使用方式()
, {}
, or .
is via subsref http://www.mathworks.com/help/matlab/ref/subsref.html, subasgn
, and subindex
,取决于上下文。
这些内置函数引用了中描述的运算符help paren
。另请探索中列出的标点符号help punct
.