In Matlab (as of 2016a) the conditional if (array_of_logicals) is functionally equivalent to if (all(array_of_logicals)). The documentation says: "An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric)."
On the other hand, assert() only accepts a "Condition to assert, specified as a valid MATLAB expression." Experimentally, this means an array_of_logicals should be used as assert(all(array_of_logicals)).
What would you say is the reason for the slightly different behavior?
I understand that one reason could be that with assert() you want to exclude the interpretation ambiguity of assert(all(array_of_logicals)) vs assert(any(array_of_logicals)), but the same could be said about if.
Aucun commentaire:
Enregistrer un commentaire