They are the same if numel(max(arr))
is 1
. If not then if tf < max(arr)
will only consider the first maximum. But since all the max(arr)
elements will have the same value it will still work.
However if you used a function that could have returned different values, such as simply
if tf < arr
vs if all(tf < arr)
then they are different. if all(tf < arr)
works as expected, if must be smaller then every element of arr
. HOWEVER if tf < arr
becomes something like if [true false true false false...]
and (thanks to Amro for pointing this out) Matlab will only conider this true if it is both non-empty and all the elemnets are non-zero. So in my made up example it will be false
. So the moral of the story is don't give if
a multi-element matrix in Matlab. So I would go for if all(tf < max(arr))
just to be consistent with that rule.