octave - how to count the row which match a combined condition? -
for example, have matrix m =
1 0 1 0 1 1; 0 1 0 1 0 1; 1 0 1 0 1 1; 0 1 0 1 0 1 i want count number of row first element m(i, 1) = 1 , third element m(i,3) = 1.
use loop work. but, hope there easy way that. octave function sum seems support 1 condition.
it's pretty easy find rows matching condition in octave:
m(:,1) == 1 # m(i, 1) = 1 m(:,3) == 1 # m(i, 3) = 1 you combine multiple conditions using octave & (logical and) , | (logical or) operators:
(m(:,1) == 1) & (m(:,3) == 1) if want number of matching roes, use sum function:
sum((m(:,1) == 1) & (m(:,3) == 1))
Comments
Post a Comment