i'm trying to retrieve an index to a variable and then using that variable to access the list.
The (simplified) code:
myList = {1, 5};
minElement = Position[myList, Min[myList]];
myList[[minElement]]
I get this error:
Part::pkspec1: The expression {{1}} cannot be used as a part specification.
The whole idea is to access other lists as well using the minElement index.
This seems like an easy question but i just can't find help about it.
Position
are to be used withExtract
. E.g.Extract[myList, minElement]
$\endgroup$Extract
is the way to go. But in some cases I've gone formyList[[#]] & @@@ minElement
instead, which gives the same answer. $\endgroup$Ordering[]
. $\endgroup$