0

I've have been using findpeaks in MatLab to locate the maximum and minimum points of a waveform with no problem, but in the last 20 minutes or so the error:

??? Subscript indices must either be real positive integers or logicals.

Has appeared an I have no idea why. Even trying simple exercises with test data has resulted in the same error. For example if I were to have the dataset:

test = [ 0.1 0.5 0.9 0.5 0.2 0.6 1.0 0.7 0.3 0.1 ]

and used the code:

peaks = test(findpeaks(test));

I would expect the result:

peaks = [0.1 0.9 0.2 1.0 0.1 ]

but for some reason this is no longer the case.

Please advise.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jazibobs
  • 422
  • 2
  • 10
  • 20
  • Also see [this question](http://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol) for [the generic solution to this problem](http://stackoverflow.com/a/20054048/983722). – Dennis Jaheruddin Nov 27 '13 at 15:49

1 Answers1

1

Findpeaks returns the peak values, not their indices. Try this.

peaks=findpeaks(test)

If you want to find the local minima as well,

peaks = [findpeaks(test) -findpeaks(-test)]
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142
  • Thanks for the quick response, but what should I add if I require the minimum values as well as the peak values? – jazibobs Apr 16 '12 at 20:55
  • the minimum values found by your code are not correct. Is there a syntax error perhaps? – jazibobs Apr 16 '12 at 21:05
  • 2
    findpeaks can actually return the indices of the peaks with the syntax `[peaks peak_indices] = findpeaks(test)` – andyras Apr 17 '12 at 04:25