Count Negative Integers in Matrix .

How to Count Negative Integers in Matrix ?

s=sign(A)
ipositif=sum(s(:)==1)
inegatif=sum(s(:)==-1)

Please explain.

@rashedcs you can run two loops to check every element of the matrix that whether it is less than zero or not.

int count=0;
for(int i=0;i<rows;i++){
    for(int j=0;j<columns;j++){
        if(matrix[i][j]<0)
            count++;
    }
}
printf("%d",count);
1 Like