在MATLAB中定义其他infix运算符 [英] Defining additional infix operators in MATLAB
问题描述
有没有一种方法可以在MATLAB中定义其他的中缀运算符?
Is there a way to define additional infix operators in MATLAB?
具体来说,我想定义两个中缀运算符->
和<->
(这些符号是理想的,但是如果需要可以是单个字符),它们在函数中调用函数implies
和iff
. &
调用and
和+
调用plus
的方式相同.
Specifically, I'd like to define two infix operators ->
and <->
(these symbols would be ideal, but it could be a single character if necessary), which call functions implies
and iff
in the same way that &
calls and
and +
calls plus
.
function z = implies(x, y)
z = ~x|y;
function z = iff(x, y)
z = x&y | ~x&~y;
如有必要,我很乐意超载logical
.
I'm happy to overload logical
if necessary.
推荐答案
由于有多个线程,如文档页面,尽管我确定您已经看过它.
There is no way to define new Operators in MATLAB as several threads like this one suggest. However, if you'd like to overload an existing operator for you own class, here's MATLAB's documentation page, though I'm sure you've already seen it.
这篇关于在MATLAB中定义其他infix运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!