Assuming you have a matrix A
, you can count the number of positive normalized elements in the following way:
main.m155 chars5 lines
In the above code, A > 0
checks if each element of A
is positive, A./max(max(abs(A)))
normalizes the elements of A
by dividing each element by the maximum absolute value of A
, and eps
is the smallest value that can be represented in MATLAB. Finally, sum(sum(...))
sums up all elements of the resulting logical matrix.
The variable count
will contain the number of positive normalized elements in the matrix A
.
gistlibby LogSnag