condition that subsets a vector , such that the value should be bigger than 0 and smaller than 5 in matlab

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.m
newVector = myVector(myVector > 0 & myVector < 5);
51 chars
2 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.

related categories

gistlibby LogSnag