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

if statementMATLABmatrix

I have 3×3 matrix and i want to write code to count the elements which are less than 3 by using if statement .

Best Answer

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.