Select certain elements from a vector and create a new vector with those elements in Matlab? -
i have vector 'y' looks this:
[1 1 1 0 1 2 2 2 2]
i use y(y>1)
command elements greater 1, in case, elements = 2
. how create new vector based off elements y(y>1)
command gave me? i'd end with
x = [2 2 2 2]
any appreciated.
you did answer own question y(y>1)
:
>> y = [1 1 1 1 1 0 0 0 2 2 2 2 2] y = 1 1 1 1 1 0 0 0 2 2 2 2 2 >> x=y(y>1) x = 2 2 2 2 2
because (y>1)
returns array of logical values size of y
containing result of given check.
>> (y>1) ans = 0 0 0 0 0 0 0 0 1 1 1 1 1
you can use array address data in data array, points logical array 1 returned
Comments
Post a Comment