How to find the number of ones in each column of a logical matrix?

6 views (last 30 days)
How to find the number of ones in each column of a logical matrix?

Accepted Answer

Star Strider
Star Strider on 11 Feb 2017
Edited: Star Strider on 11 Feb 2017
Use the sum function.
Example:
A = logical(randi([0 1], 10,5)); % Create Data
Ones_In_Each_Column = sum(A) % Sum The Columns
EDIT Added ‘Example’ code.
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!