Findall() but returning a bool array

Hi all,

I would have liked the findall() function to return booleans.

Code example:

A = [1 2; 3 4]
B = findall(>(2),A)
C = [0 0; 1 1]
B == C

This code will obviously return false at the B==C assertion. What should I use if I want B to be an array of the same dimension as A but containing booleans (0 for this coordinate does not satisfy the condition, 1 for this coordinate satisfies the condition).

Thank you for your attention.

EDIT: I made a comparison with matlab that was wrong. Thus I deleted the sentence.

B = A .> 2

?

1 Like

This is Matlab code:

>> A = [1 2; 3 4]
 
>> B = find(A>2)
B =
     2
     4

>> A > 2
ans =
  2×2 logical array
   0   0
   1   1

In other words, Julia already behaves pretty much like Matlab does, except that findall returns a vector of cartesian indices instead of linear indices.

1 Like

I corrected the mistake in the post where I mentioned matlab.