You can use logical indexing to subset a vector with a condition.
Assuming your vector is called myVector
, the following code will give you a new vector with elements between 0 and 5:
main.m51 chars2 lines
Explanation: myVector > 0
creates a logical index of elements greater than 0, myVector < 5
creates a logical index of elements less than 5, and &
combines them as a logical AND. The resulting logical index selects only those elements of myVector
that satisfy both conditions.
gistlibby LogSnag