I have a vector of negative values like this:
values = [-15, -6.45, -3.75, -5.55, -2.40]
i want to know which of these is the smallest and the corresponding index. I try using min
function but i ran into this error:
Subscript indices must either be real positive integers or logicals.
How can i solve this annoying problem?
I think you are trying to use the direct output of
min
to access an entry in an array. The return value ofmin
is the actual minimum value not the index in the array.To get the value and the index try using the following code:
This will return
minval = -15
andminindex = 1
. Withminindex
you can address an entry in an array. For example in thevalues
-array:This returns of course
-15
.