How to compare each element of matrix to specific number and count it ?

1 view (last 30 days)
I have 3x3 matrix and i want to write code to count the elements which are less than 3 by using if statement .

Accepted Answer

Adam Danz
Adam Danz on 13 Sep 2020
Edited: Adam Danz on 13 Sep 2020
m is your matrix, n is the number of values less than 3.
n = sum(m<3,'all')
There's no need for an if-statement.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!