Respuesta aceptada

Jan
Jan el 1 de Oct. de 2017
Editada: Jan el 1 de Oct. de 2017
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.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 1 de Oct. de 2017

Editada:

el 1 de Oct. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by