Info

This question is closed. Reopen it to edit or answer.

How do I count to occurences of a number in an unsanitized array

1 view (last 30 days)
Say I have cell A, with values:
0
0
1
[0; 1; 0]
1
Now I want to count the occurences of 1 is this matrix, and [0; 1; 0] should be ignored.
However, when I do:
amount_correct = sum(A == 1);
I get an error as soon as it arrives at [0; 1; 0].
I however simply want it to give as output 0 and move on to the next element of the array till I get to the end.
The eventual output should be 2.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!