MATLAB: How can i calculate how many number of times that 1 occurs.

how can i calculate how many number of times that 1 occurs.

I have an array like this
x =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
how can i calculate how many number of times that 1 occurs.

Best Answer

x=repmat(1:4,4,1) % Example
out=sum(x(:)==1)
%or
out=nnz(x==1)