MATLAB操作符通常被翻译成函数形式,例如以下示例:
~A
=>not(A)
A + B
=>plus(A,B)
A(...)
=>subsref(...)
A(...) = ...
=>subsasgn(...)
- 等等。
现在请考虑运算符 &&
和 ||
。
help and
、help or
、help relop
也没有。这个也没有帮助:profile('on','-detail','builtin')
。我可以说的是,根据以下示例,
|
似乎被重定向到or()
:>> 1 || [0,0]
ans =
1
>> 1 | [0,0]
ans =
1 1
>> or(1,[0,0])
ans =
1 1
>> 1 && [0,0]
Operands to the || and && operators must be convertible to logical scalar values.
所以我的问题是:假设可能的话,如何显式调用
&&
和||
的基础函数?(注意:这个问题涉及“如何”的方面,而不是“为什么”)
&&
和||
就是MATLAB具有惰性求值能力的“活生证明”...问题是为什么我们不能像这样轻松地利用MATLAB的这些能力来做其他事情呢? - Dev-iLsAND(@() expr1, @() expr2, ...)
可能是最接近的了。 - knedlseppif
,当OP问这个问题时。这就是为什么它非常相似的原因。;-) - knedlsepp