Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a list of X values and Y values separately, and also together with:


This data is from a chromatogram, and I want to extract the retention time tR (X) that corresponds to the highest value of absorbance (Y). I normally perform an interpolation with


For some reason this approach is not working with a recent chromatogram, and I wanted to extract the X value that corresponds to the maximum Y value directly from the two lists like this:


This gives me the position in the vector where I can find the X value I want. If I input the value manually I get the X value I am looking for:


So far so good. However, if I try to assign Position[Y,Max[Y]] to a variable (for automation, since I have a program that does all the data extraction and plotting for me), I cannot get the X value:


Part::pspec: Part specification {{9970}} is neither a machine-sized integer nor a list of machine-sized integers. >>

This isn't working either:


Any help will be very welcome.

share|improve this question

closed as off-topic by Kuba, Öskå, acl, Sjoerd C. de Vries, m_goldberg Jun 10 '14 at 15:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, Öskå, acl, Sjoerd C. de Vries, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

X[[ymaxposition[[1,1]]]] –  Kuba Jun 10 '14 at 9:35
What Kuba said. And I assume there will not be more than one maximum in Y? Else you'll want to be sure to handle that appropriately. –  rasher Jun 10 '14 at 9:38
@Kuba. Perfect. Thank you. –  PMG870505 Jun 10 '14 at 10:30
Position provides the result in a format that is suitable for use with Extract. Braces are used to indicate the depth/level of the results. –  Sjoerd C. de Vries Jun 10 '14 at 14:16

2 Answers 2

up vote 2 down vote accepted

Why don't you pick the X value directly from data? something like this:

Sort[data, #1[[2]] > #2[[2]] &][[1, 1]]
share|improve this answer
Excellent. Thank you. Also X[[ymaxposition[[1,1]]]] worked –  PMG870505 Jun 10 '14 at 10:31

Try this:

Select[data,#[[2]]==Max[Y]&][[All, 1]]

or shorter

Pick[X, Y, Max[Y]]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.