I have Table with 10000 elements in it and I plot a graphic using ListPlot. enter image description here

I need find minimum in graph. enter image description here

Here is a .txt file with data.

I tried to use


the result is 0., cuz it search the first point of x but I don't need the first one.

  • $\begingroup$ Data[[Ordering[Data[[All,2]],1][[1]],1]]? $\endgroup$ – Henrik Schumacher Feb 10 at 15:56

This is how I would go about it:

minIndex = data[[All, 2]] // MinDetect // PositionIndex;

Now all the positions of the minima were collected in an Association and given the key 1. We now want to split the list of minima positions into sublists that are "connected", e.g. where each position is separated by a distance of 1. From these sublists we only need the first and the last positions (the "corners"):

minPositions = minIndex[1] // RightComposition[
    Split[#, #1 == #2 - 1 &] & (* distance could be made more "soft" of course *)
    , Part[#, All, {1, -1}] &
    , Flatten

{1, 276, 1167, 2844}

We now Extract the data points for these positions dropping the first, which you do not need as you said:

minPoints = Extract[data, List /@ minPositions] // Drop[#, 1] &

{{0.275, 0.}, {1.166, 0.}, {2.843, 0.}}


ListPlot[ data, Epilog -> {Red, PointSize -> Large, Point@minPoints }, ImageSize -> Large ]

ListPlot of data with minima

lp = ListLinePlot[data, 
  MeshFunctions -> {#2 &}, 
  MeshStyle -> Directive[Red, PointSize[Large]], 
  Mesh -> {{Min[data[[All, 2]]]}},
  AxesOrigin -> {0, -.01}]

enter image description here

To extract the data elements:

Cases[Normal @ lp, Point[x_] :> x, All]

{{0., 0.}, {0.275, 0.}, {1.166, 0.}, {2.843, 0.}}

If you want to remove the first point:

lp /. Point[x_] :> Point[Rest @ x]

enter image description here


This should do:

MinimalBy[Data, Last]

If you have runs of minimal elements and only want the first and last one: assuming that the grid spacing is 0.001 and inserting 10% of tolerance,

Split[MinimalBy[Data, Last], #2[[1]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]

maybe combined with Flatten to make into a single list of points.


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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