matlab - How to count number of 1's in the matrix -


i have 1 matrix like-

a=[1 1 3 0 0;    1 2 2 0 0;    1 1 1 2 0;    1 1 1 1 1]; 

from these "a" need count number of 1"s of each row , after want give condition after scanning each row of 'a' if number of 1's >=3 take that. means final result

a= [1 1 1 2 0;     1 1 1 1 1]. 

how can this. matlab experts need valuable suggestion.

>> a(sum(a == 1, 2) >= 3, :)  ans =       1     1     1     2     0      1     1     1     1     1 

here, sum(a == 1, 2) counts number of ones in each row, , a(... >= 3, :) selects rows count @ least 3.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -