I have a question regarding the internal code of the findall function. I have an array and I want to find elements that satisfy two conditions. I know that I can use something like findall(f:function,A) where A is the array. I have the following code:
A = [1;2;3;4;5];
The first two commands return the correct answer: 2,3. The third one returns 2,3,4,5 and the fourth one returns 0-element Array.
Why don’t the last two commands work?
The logical and works with or without the brackets (command 2). I was just curious why the bitwise operation doesn’t work as I would imaging the function generates two bits for each element of the array and then computes the and operation, which should result in the correct answer. I found information on the precedence for && and || but not on bit wise operations.
I finally understand it now. It evaluates 1&x as a quantity, since x is nonzero, the value is computed as 1, then the conditions read as x>1<4 which is true. Thus the result is true, when you put them in the bracket it evaluates it as two conditions and gives the right answer.
The same logic applied to my initial question. The third condition reads as: x>1<4 (since all my entries are nonzero), all values other than the first satisfy the condition, thus the answer. The fourth condition reads as x<1>1 which is not true thus it doesn’t return anything.