MATLAB: Count even elements vector

even numbersMATLABmod

I have wrote this to identify the even numbers x = vec(mod(vec,2)==0); how do I edit it so it returns how many integers of even numbers there are within this single command.

Best Answer

Isn't it trivial? Using sum:
sum(mod(myvec, 2) == 0)
Or using nnz:
nnz(mod(myvec, 2) == 0)