Dear Vitaliy,
Thank you very much! This is just what I needed. My problem is that I was not aware of the existence of the FindPeaks function, so of course I was trying to figure out how to do this in a functional way. And I just could not figure out how. The strange thing, at least to me, is that I can figure out how to implement the algorithm in 5 seconds if I need to get it done in C++ or in C#. I can then write it out in 30 seconds. THAT is what makes learning Mathematica so frustrating to me. Mathematica is the MOST POWERFUL programming language I know, but figuring out how to do things can be a long trek. There are so many functions available out there, one of which probably being EXACTLY the one you need, but unknown to you unless you read about all the functions and go "Oh, My God! Here is the function I need".
But thank you very much. This is what I needed. I will still have to look at "valleys = {1, -1} # & /@ FindPeaks[-testList];" to see what it does. I can see that it multiplies the list by -1 in order to turn valleys into peaks. I am not sure what "{1, -1} # & /@" does to the result. But will look at it.
Something else. I also received an answer from David Reiss.
Here it is:
In[1]:= testList = {10, 5, 3, 6, 9, 15, 13, 12, 9, 15, 18, 20, 19, 18};
In[2]:= peakTrippleQ[{x, y, z_}] := TrueQ[x < y > z]
In[3]:= peakPositions[list_List] :=
Flatten[Position[peakTrippleQ /@ Partition[list, 3, 1], True] + 1]
In[4]:= valleyTrippleQ[{x, y, z_}] := TrueQ[x > y < z]
In[5]:= valleyPositions[list_List] :=
Flatten[Position[valleyTrippleQ /@ Partition[list, 3, 1], True] + 1]
In[6]:= peakPositions[testList]
Out[6]= {6, 12}
In[7]:= valleyPositions[testList]
Out[7]= {3, 9}
I am grateful to him too. However, his answer was, at least to me, incomprehensible (and I am not blaming him). My point is how 2 knowledgeable people can come up with 2 such different answers. One incomprehensible (and not doing quite what I need) and one almost totally clear. It makes you wonder, as a novice, how am I supposed to do this efficiently? I could use the procedural approach, but I know (based on a Wolfram Alpha Video I viewed) that the preferred, and most time efficient way, is to use the functional approach.
So, I have a couple of questions for you Vitaliy. How long have you been writing code in Mathematica? Do you write in one of the other Procedural or Object-Oriented Languages like C++? How did you know about FindPeak? Did you just happen to read some book on Mathematica and saw that there is such a function? I am just curious to see how others learn this extremely powerful language, yet, in my view, difficult language to get one's mind wrapped around.
Again, Thank you very much for your answer Vitaliy,
Regards,
Henrick
P.S. Is there a way to CC: someone when replying? I would have liked to CC: David on this response.