To find the largest positive element from a given matrix/vector, we can use the following code snippet:
main.m42 chars3 lines
In this code, we first define the vector f
as [2, -5, 5, 4]
. We then use the max()
function with a logical index of f > 0
to find the maximum of only the positive elements in f
. The final result is stored in the variable m_inf
.
Note that if there are no positive elements in f
, m_inf
will be empty, so you may want to add a check for this condition.
gistlibby LogSnag