what's the difference between | and || in matlab??

342 次查看(过去 30 天)
what's the difference between | and || in matlab??

采纳的回答

matt dash
matt dash 2014-12-10
移动:Stephen23 2024-3-19
Clarification: for short circuit "and" no tests are evaluated after the first "false". For short circuit "or" no tests are evaluated after the first true.

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2014-12-10
编辑:Sean de Wolski 2014-12-10
| applies to each element in the array, || applies to a scalar condition:
[1 0 1] | [ 0 0 1]
v.
[1 0 1] || [ 0 0 1]
  1 个评论
Stephen23
Stephen23 2024-3-19
编辑:Stephen23 2024-3-19
It is unclear to me what those code examples are supposed to clarify:
[1 0 1] | [0 0 1]
ans = 1×3 logical array
1 0 1
[1 0 1] || [0 0 1]
Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write Unit Tests 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by