??? Subscript indices must either be real positive integers or logicals. Using findpeaks
Mostrar comentarios más antiguos
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.
Thanks,
Jared.
2 comentarios
Walter Roberson
el 16 de Abr. de 2012
Where does it say that the problem is occurring? Which line, which file?
Jared Rigby
el 16 de Abr. de 2012
Respuesta aceptada
Más respuestas (2)
Richard Brown
el 16 de Abr. de 2012
You've probably declared a variable called findpeaks by accident. Try
which findpeaks
and confirm it's actually pointing to a function
3 comentarios
Sean de Wolski
el 16 de Abr. de 2012
clear findpeaks
to remove the variable overwriting it
Jared Rigby
el 16 de Abr. de 2012
Jared Rigby
el 16 de Abr. de 2012
Wayne King
el 16 de Abr. de 2012
[pks,locs] = findpeaks(test);
pks
test(locs)
pks contains the peak values
locs are the indices
test(locs)
5 comentarios
Jared Rigby
el 16 de Abr. de 2012
Wayne King
el 16 de Abr. de 2012
you mean the maximum and minimum peak?
sort(findpeaks(test))
If you just want the min and max elements of the vector, then just use min(), max()
Jared Rigby
el 16 de Abr. de 2012
Image Analyst
el 16 de Abr. de 2012
He wants the valleys. In my answer I recommended Jared invert the data and run findpeaks again. Valleys will turn into peaks once you've inverted it.
Richard Brown
el 16 de Abr. de 2012
haha, I blame TMW for this confusion (pks vs locs). findpeaks suggests that it returns indices a. la. find, you'd actually want it to be called peaks. But we can't have that, can we!
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!