How do you get Matlab to return a value for how many 1's are in a vector containing just 1's and zeros
Show older comments
Like if i have greencars=[11111111000000000000] how to i get Matlab to count how many ones there are?
Accepted Answer
More Answers (3)
Adrian Jimenez-Galindo
on 29 Nov 2012
1 vote
You can use Count(greencars, '==1') Hope this helps.
Azzi Abdelmalek
on 29 Nov 2012
a=[1 0 1 1 0 0 0]
numel(find(a))
Walter Roberson
on 29 Nov 2012
nnz(greencars)
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!