how to select rows of a matrix on the basis of occurrence of elements in matlab? -
i have [sentence cross words] matrix follows.
x = [ 0 1 1 0 1 1 1 1 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 ];
0
shows word present in respective sentence , 1
shows word absent in respective sentence, have done processing , selected word number 2,3 , 5
columns. want select sentences (rows) on basis of word 2,3 , 5
in 2 or more 2 words appear, single appearance of word in sentence should not considered
for example above matrix sentence number 1, 2 , 4 should selected because word 2,3 , 5
occurs in them , sentence number 3 , 5
should not considered because in sentence 3
word 3 appears alone without 2 , 5
. if there 2
or 5
present in sentence 3
should selected because more 2 words occured in senence.
one approach select valid rows x
-
x_valid = x(sum(x(:,[2 3 5]),2)>=2,:)
instead, if interested in knowing valid indices -
idx = find(sum(x(:,[2 3 5]),2)>=2)
sample run -
x = 0 1 1 0 1 1 1 1 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 x_valid = 0 1 1 0 1 1 1 1 0 0 1 1 0 1 1 idx = 1 2 4
Comments
Post a Comment