我只是好奇,MATLAB中的所有運算符是否都在內部實現爲函數?對於幾乎所有的MATLAB運算符,我們都有相同的功能plus
對於+
,minus
對於-
,eq
對於==
和transpose
對於'
。MATLAB運算符作爲函數
5
A
回答
3
是的,這就是MATLAB通過映射中綴運算符到命名函數來實現運算符重載的方法。
documentation列出(按類別)由操作員調用的函數。和more here。
5
大多數運營商都是由功能來表示的,是的。
提供Implementing Operators for Your Class 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
。 horizontal與vertical串聯用逗號分隔的列表:
>> c = {'a','b'};
>> horzcat(c{:}) % [c{1} c{2}]
ans =
ab
>> vertcat(c{:}) % [c{1};c{2}]
ans =
a
b
除了許多其他書面運營商命名的功能,有一對夫婦無證的,你可以訪問(colon
,transpose
,等等。)與builtin
:
括號
>> 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
然而,注意適當和支持的方式來使用()
,{}
,或.
是通過subsref
,subasgn
和subindex
,這取決於上下文。
這些builtins指的是help paren
中描述的操作符。同時探索help punct
中列出的標點符號。
相關問題
- 1. Matlab運算符
- 2. Matlab運算符**
- 3. 運算符(操作數?)作爲參數
- 4. 行爲遞增運算符作爲參數傳遞給函數
- 5. 運算符不解析爲運算符函數C++
- 6. 作爲字符的數學運算符
- 7. 函數句柄和數組運算符 - Matlab
- 8. 作爲成員函數和非成員函數的運算符函數
- 9. 將運算符作爲參數傳遞給函數C
- 10. 通過< or >運算符作爲參數的函數?
- 11. JavaScript邏輯運算符作爲函數的參數
- 12. 通過運算符作爲函數模板參數
- 13. 重載函數運算符
- 14. 重載運算符函數==
- 15. 定義運算符()函數
- 16. matlab布爾運算符
- 17. MatLab的運算符重載
- 18. Numpy vs mldivide,「\」matlab運算符
- 19. 〜=在Matlab中的運算符
- 20. MATLAB - 對數運算符錯誤
- 21. 使用`**`作爲運算符運算符快速運行,運算符'-`
- 22. 傳遞一個運算符作爲函數
- 23. Rust是否支持使用中綴運算符作爲函數?
- 24. 在C中實現模運算符作爲函數C
- 25. 作爲成員函數重載*乘法運算符兩次?
- 26. 運算符超載作爲朋友函數錯誤
- 27. 使用運算符作爲序言中的構造函數
- 28. 與函數運算符組合函數不能正常工作
- 29. 如何在LISP中將算術運算符作爲函數參數傳遞?
- 30. 三元運算符作爲C宏中三元運算符的操作數
感謝您的回答。這[鏈接](http://nf.nci.org.au/facilities/software/Matlab/techdoc/matlab_prog/ch14_o23.html)列出瞭如何重載一個操作符。 – erbal