0

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

data=Transpose[{X,Y}]

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

f=Interpolation[data];
tR=x/.Last[FindMaximum[f[x],{x,1}]];

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:

Position[Y,Max[Y]]

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:

X[[9970]]

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:

ymaxposition=Position[Y,Max[Y]];
tR=X[[ymaxposition]]

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

This isn't working either:

Position[Y,Max[Y]]
tR=X[[%]]

Any help will be very welcome.

PMG870505
  • 165
  • 7

2 Answers2

2

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

Sort[data, #1[[2]] > #2[[2]] &][[1, 1]]
Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
2

Try this:

Y={1,3,4,1,2,3,5,5,2};
X=Y-1;
data=Transpose[{X,Y}];
Select[data,#[[2]]==Max[Y]&][[All, 1]]

or shorter

Pick[X, Y, Max[Y]]
molekyla777
  • 2,888
  • 1
  • 14
  • 28