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

1 view (last 30 days)
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.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 13 Dec 2014
Edited: Azzi Abdelmalek on 13 Dec 2014
x=repmat(1:4,4,1) % Example
out=sum(x(:)==1)
%or
out=nnz(x==1)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!