Showing results for 
Search instead for 
Did you mean: 

index array using boolean array

Given "y" as an N-element array of doubles randomized using a normal distribution, the following is true.


In MatLab (R2014a) you can do this:


is_gt_zero = (y>0)
y_subset = y[is_gt_zero]


and get an array comprised of the positive elements of "y".


In "R" you can do this:

is_gt_zero <- which(y>0, arr.ind=F)
y_subset <- y(is_gt_zero)

and get the same. 


LabView has the "In Range and Coerce" vi.  It gives a boolean array, but I am not finding boolean indexing. I really don't like nesting for loops.  Is there a way to not do that?

Do I need to wrap a for loop around the boolean array and look for true indices, or is there a cleaner way to do boolean-driven indexing?


0 Kudos
Message 1 of 3

Try something like this.



Message 2 of 3

A simple FOR loop with conditional autoindexing tunnel should do the trick for you.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 3