findpeaks returns the peak, which is 0.9, if you don't accept both output arguments of it. 0.9 in not an integer and so it cannot be used as as index into test. Since you want the peaks, and that's what findpeaks returns, you can simply do this:
testData = [ 0.1 0.5 0.9 0.5 0.2 0.6 1.0 0.7 0.3 0.1 ]
peaks = findpeaks(testData)
and get the results:
testData =
0.1000 0.5000 0.9000 0.5000 0.2000 0.6000 1.0000 0.7000 0.3000 0.1000
peaks =
0.9000 1.0000
These are the peaks, but this does not match what you're calling peaks. It looks like you're including the valleys in how you define peaks. In that case, you might want to run findpeaks again on the inverted data (subtract your data from the max of the data).
maxPeakValue = max(peaks);
invertedData = [0, maxPeakValue - testData, 0]
valleys = maxPeakValue - findpeaks(invertedData)
Best Answer
If y is the function of the plot -y will give the minimum of the function.