Counting the amount of number 1

4 views (last 30 days)
How can I insurt the category name and count the amount of number 1?
For example, I have a matrix but there are only numbers:
1 0 0 0 1 1 1
1 1 0 0 0 0 0
1 1 1 1 1 0 0
0 0 0 1 0 0 1
I want to count the amount of number one from the first low to last. Therefore, computed number should be this:
3 2 1 2 2 1 2
How can I get these numbers?
Thank you for you attention to this question and have a nice day :)

Accepted Answer

David Hill
David Hill on 1 Mar 2022
Count=sum(yourMatrix==1);%assuming other than 1's and 0's are possible

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!