You can use the following code to count the number of positive normalized elements in the given array:
main.m94 chars5 lines
Here, we first calculate the L1-norm of the array using norm(f,1)
function. Then, we divide each element of the array by the L1-norm to get the normalized array f_norm
. Finally, we count the number of elements in f_norm
that are greater than 0 using sum(f_norm > 0)
function.
Note that the array f
in the given question is not in valid matlab syntax, so I assumed it to be [2, -4, 7, 5]
.
gistlibby LogSnag