Please help me with coding up "-5 < x < 3"

 采纳的回答

Jan
Jan 2017-10-1
编辑:Jan 2017-10-1
It depends on what "x" is and what you want as output. Please post more details, because letting the readers guess the intention is not efficient.
Perhaps you want:
if -5 < x && x < 3 % Equivalent: and(-5 < x, x < 3)
or
Mask = and(-5 < x, x < 3); % If x is an array
Maybe "x" is a symbolic variable or you want to use this as restriction for an optimization? Or you want to display the formula formatted by LaTeX in a title?
If you write "-3<x<5" directly, the result may be unexpected: Matlab evaluates this from left to right. "-3<x" is either TRUE or FALSE. In the next step you get "true<5" or "false<5", and because the logical values are treated as numerical 0 and 1, both relations are true independent from the value of x.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by