I am looking for a minimal value in an array which is larger than a certain number. I found this discussion which I don't understand. There is MINLOC
, but it looks like it does not do as much as I would like on its own, though I didn't parse the arguments passed to it in the given examples. (It is also possible to do this using a loop but it could be clumsy.)
2 Answers
You probably want MINVAL.
If your array is say,
array = (/ 21, 52, 831, 46, 125, 68, 7, 8, 549, 10 /)
And you want to find the minimum value greater than say 65,
variable = minval(array, mask=(array > 65))
which would obviously give 68.
It sounds like MINVAL
is what you want.
You just need to do something like:
min_above_cutoff = MINVAL(a, MASK=(a > cutoff))
The optional parameter MASK
should be a logical array with the same size as a. It tells MINVAL
which elements in a to consider when searching for the minimum value.
Take a look at the documentation here: MINVAL
If you would instead like to get the index of the minimum value, rather than the value itself, you can use MINLOC
. In this case the code would look like:
index = MINLOC(a, MASK=(a > cutoff))
Documentation can be found here: MINLOC
-
1
minloc
returns the location of the variable, not the value at that location (the latter being what the OP wants).minval
is what the OP is looking for, see my post. Dec 18, 2013 at 3:47 -
Yup you are totally right. I updated my answer to reflect this. Your answer is more concise with an example though, so +1 to you.– amicitasDec 18, 2013 at 4:14
-
1Please re-add a
minloc
example. It may be useful to the readers: note the (intentionally) slightly broad scope of the question title.– user649198Dec 18, 2013 at 5:39