我很好奇MATLAB中的所有运算符是否都在内部实现为函数?我们几乎所有MATLAB运算符都有相同的函数.plusfor +,minusfor -,eqfor ==和transposefor '.
大多数运营商都由功能代表,是的.
MathWorks页面为您的类实现操作符提供了一个完整的列表,在此处转载:
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,它使用非常强大的虚拟数据复制来应用任何元素功能.
经常有用的是vertcat.水平与垂直连接以逗号分隔的列表:
>> c = {'a','b'};
>> horzcat(c{:}) % [c{1} c{2}]
ans =
ab
>> vertcat(c{:}) % [c{1};c{2}]
ans =
a
b
Run Code Online (Sandbox Code Playgroud)
除了许多其他具有命名函数(colon,transpose等)的文档化操作符之外,还有一些可以访问的未记录的操作符builtin:
插入语
>> x = [4 5 6];
>> builtin('_paren',x,[2 3]) % x([2 3])
ans =
5 6
Run Code Online (Sandbox Code Playgroud)
大括号
>> c = {'one','two'};
>> builtin('_brace',c,2) % c{2}
ans =
two
Run Code Online (Sandbox Code Playgroud)
struct field access(dot)
>> s = struct('f','contents');
>> builtin('_dot',s,'f') % s.f
ans =
contents
Run Code Online (Sandbox Code Playgroud)
但是,请注意,正确的和支持的方式来使用(),{}或者.是通过subsref,subasgn和subindex,根据上下文.
这些内置引用了中描述的运算符help paren.还要探讨列出的标点符号help punct.